socialize.publishUserAction

Last modified 06:05, 30 Mar 2015

Description

Publishes a user action to the newsfeed stream on all the connected providers that support this feature.

To learn more about publishing newsfeed items, please read the Advanced Sharing page in the Developer's Guide.

Note: This method is also supported in our REST API. If you wish to execute this method from your server, please refer to REST API > socialize.publishUserAction.

 

Supporting Providers

The following providers currently support this operation: Facebook, TwitterLinkedIn, VKontakte*, Tencent QQRenren and Sina Weibo.

 

Note:
  • The VKontakte application must be whitelisted in order for it to support share.
  • Before your application can publish to Facebook, the user must grant your application an extended permission. During the social login process, the user is presented with a dialog in which the user can authorize your application to publish to her Facebook profile. Read more in the the Facebook Setting - Permissions guide.

 

Possible Responses and the "Unsupported Provider" Error

When publishUserAction is called, the Gigya server tries to publish the user action to every provider to which the user is connected that is also listed in the 'enabledProviders' parameter. If the server succeeds in publishing to at least one of these providers, it considers the operation successful. An error is returned only if the server cannot publish to any of these providers.

In other words, if you call publishUserAction and specify an unsupported provider in 'enabledProviders', the call might still succeed if the user has other valid connected providers -- or it may fail for other reasons, e.g. an expired session on a supported provider.

The server returns an 'unsupported provider' error only if the user is connected to that unsupported provider and has no other valid connections.

 

Syntax

gigya.socialize.publishUserAction(params)

 

Method Parameters

The following table lists the params object members:

Required Name Type Description

Required

userAction

UserAction object The user action to publish.
Notes: 
  • A shared URL must match the approved URLs (domains) for the specified API key, otherwise the share will not work. 
  • When Twitter is the provider, only the Title and Link Back are posted.
Optional actionAttributes JSON object In Gamification your users receive points for actions they perform on your site, in this case publishing a user action grants the user points. Action Attributes may be used to annotate actions with additional information, such as the section of the web site that generated the action. If you set here the actionAttributes, each time a user publishes a user action, the action also receives an attribute, for example "tv-show":"glee", which can mean that the action was performed on the "Glee" page of the site. 
actionAttributes contain a JSON object comprised of a series of attribute keys (categories) with associated values. You can also use a generic "tags" key. No more than three values can be given, they can be with a single key or each have their own key. For more information see Variants and Action Attributes. Action attributes are later used to filter GM Plugins by a certain attribute.
Example:  {"<attribute key1>": ["<attribute value1>", "<attribute value2>"],  "<attribute key2>": "<attribute value3>" } 
  callback function A reference to a callback function. Gigya calls the specified function along with the results of the API method when the API method completes.
The callback function should be defined with the following signature: functionName(response).
The "Response object Data Members" table below provides specification of the data that is passed to the callback function.
  cid string A string of maximum 100 characters length. The CID sets categories for transactions that can be used later for filtering reports generated by Gigya in the "Context ID" combo box. The CID allows you to associate the report information with your own internal data. For example, to identify a specific widget or page on your site/application. You should not define more than 100 different context IDs.
Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.
  context object A developer-created object that is passed back unchanged to the application as one of the fields in the response object.
  disabledProviders string A comma-delimited list of provider names to exclude in the method execution. This parameter gives the possibility to specify providers to which that you don't want this method to apply. If you do not set this parameter, by default no provider is disabled (i.e. the method applies to all connected providers).
For example, if you would like the method to apply to all providers except Google+ and Twitter, define: disabledProviders: "googleplus, twitter".
Valid provider names include: 'facebook', 'twitter', 'linkedin', 'vkontakte''qq', 'renren', 'sina'.
Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.
  enabledProviders string A comma-delimited list of provider names to include in the method execution. This parameter gives the possibility to apply this method only to a subset of providers of your choice. If you do not set this parameter, by default all the providers are enabled (i.e. the method applies to all connected providers).
For example, if you would like the method to apply only to Facebook and Twitter, define: enabledProviders: "facebook, twitter".
Valid provider names include: 'facebook', 'twitter', 'linkedin', 'vkontakte', 'qq', 'renren', 'sina'.

The VKontakte application must be whitelisted in order for it to support share.​

Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.
  shortURLs string

Using this parameter you may determine whether to use Gigya's URL shortening service for URLs passed in the status parameter. The optional values for this parameter are:

  • 'always' (default): always try to shorten URLs. Where providers permit, URLs are shortened based on the Data Center you are using.
    fw.to for US DC.
    shr.gs  for users of the European data center.
    vst.to for Australian DC.
  • 'whenRequired': URLs longer than 139 characters are shortened in accordance with provider preferences.
  • 'never' - never shorten URLs. Where providers permit, URLs are left untouched.

URL shortening requirements vary between providers and depend on the particular type of action and its content. URL shortening is available for the following providers:

Provider Note
Facebook  
Twitter  
LinkedIn Shortened URL is posted to the social network but traffic reports show abbreviated URL (e.g., http://developers.gigya.com/020_Clie...showShareBarUI is abbreviated to developers.gigya.com)
Messenger Not for share
Delicious Shortened URL is posted to the social network but traffic reports show abbreviated URL (e.g., http://developers.gigya.com/020_Clie...showShareBarUI is abbreviated to developers.gigya.com)
WhatsApp Only on mobile
Reddit  
GooglePlus  
Google Bookmarks  
VKontakte  
nk.pl  
Xing  
Tuenti  
Hatena  
Pinterest Shortened URL is posted to the social network but traffic reports show abbreviated URL (e.g., http://developers.gigya.com/020_Clie...showShareBarUI is abbreviated to developers.gigya.com)
Baidu  
FriendFeed  
Tumblr  
Skyrock  
Sina  
mixi  
Kaixin  
VZnet  

When Gigya's URL shortening service is active, Gigya tracks all the traffic coming from the distributed URLs. In such case, 'Referred Traffic' reportswill be available to you.


Note: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.
  tags string A comma separated list of tags that are used to identify the share operation.
  <provider-name>UserAction UserAction object It is possible to specify a different content to publish for each social network. For this purpose, the method supports a set of parameters with the same name format: <provider-name> (i.e. facebook, twitter, etc.) followed by "UserAction". For example: twitterUserAction - specifies the content to be used specifically when publishing to Twitter.
Each of these optional parameters accepts a UserAction object and if specified override the userAction parameter when publishing to that provider. In other words, the userAction parameter (see above) specifies the default content to be used for all social networks and <provider-name>UserAction specifies the content to be used for the specific network.
  userLocation JSON Object The location to which this user action refers. Assigning a location to a user action is currently supported by Twitter only. The value of this parameter should be a JSON object containing the following fields:
  • longitude - the longitude of the location. The valid ranges for longitude is -180.0 to +180.0 (East is positive) inclusive.
  • latitude - the latitude of the location. The valid ranges for latitude is -90.0 to +90.0 (North is positive) inclusive.
  • placeID - a unique identifier of a place to which this status update refers.
    Note: you may receive a list of place identifiers using the socialize.getPlaces method.
See also socialize.checkin.
Activity Feed Plugin related Parameters:
The following parameters are relevant only if you are integrating the Activity Feed Plugin in your site
  scope string When publishing feed items, by default the feed items are published to social networks only and will not appear on the site's Activity Feed plugin. To change this behavior, you must change the publish scope. The optional values for this parameter are:
  • 'internal': the feed item will be published inside the site scope only and will appear on the Activity Feed plugin.
  • 'external' (default): the feed item will be published externally to social networks and will appear on social networks' feed streams (but not on the site's Activity Feed plugin).
  • 'both': the feed item will be published internally to the site and externally to social networks. The feed item will appear both on social networks' feed streams and on the site's Activity Feed plugin.
  privacy string The privacy level determines how the user action is presented in each of the Activity Feed plugin tabs. The optional values for this parameter are:
  • 'public' - Public items appear in all tabs with the publisher's identity (user name and image).
  • 'friends' - Friends items appear in the 'Friends' and 'Me' tabs with identity, and anonymously in the 'Everyone' tab.
  • 'private' (default) - Private actions appear in the 'Me' tab, and anonymously in the 'Friends' and 'Everyone' tabs. An exception to this rule: If the item has been shared to social networks, then it will be presented as "identified" (with the user name and image) in the 'Friends' tab
  feedID string The purpose of this parameter is to support multiple Feed Streams with different feeds on the same domain. You may give a different feedID to different Activity Feed plugins in your site. The Activity Feed plugin shows only User Actions that are published with the same feedID (please refer to the same parameter in the showFeedUI method).
Using this parameter you may choose to which Activity Feed plugin on your site this User Action will be published. If this parameter is not set, it will be published on an Activity Feed plugin that has no feedID (default).

 

Response Object Data Members

Field Type Description
errorCode integer The result code of the operation. Code '0' indicates success, any other number indicates failure. For a complete list of error codes, see the Error Codes table.
errorMessage string A short textual description of an error associated with the errorCode for logging purposes.
operation string The name of the API method that generated this response.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.
providerPostIDs array An array of JSON objects representing the social network's post ID. Each object has the following fields:
  • provider - the social network provider (string). The optional values are: 'facebook', 'twitter' and 'linkedin'.
  • postID - the unique ID of the post (string).

 

Code Sample

// Constructing a UserAction Object
var act = new gigya.socialize.UserAction();

act.setTitle("This is my title");  // Setting the Title
act.setLinkBack("http://www.gigya.com");  // Setting the Link Back
act.setDescription("This is my Description");   // Setting Description
act.addActionLink("Read More", "http://www.gigya.com");  // Adding Action Link
// Adding a Media (image)
act.addMediaItem( { type: 'image', src: 'http://www.infozoom.ru/wp-content/uploads/2009/08/d06_19748631.jpg', href: 'http://www.gigya.com' });
			
var params = 
{
    userAction:act
};

// Publishing the User Action			
gigya.socialize.publishUserAction(params);

Notes:
  • This sample is not meant to be fully functional code. For brevity's sake, only the code required for demonstrating the API call itself is presented.
  • To run the code on your own domain, add your Gigya API key to the socialize.js URL. A Gigya API key can be obtained on the Site Dashboard page on Gigya's website. Please make sure that the domain from which you are loading the page is the same domain name that you used for generating the API key.
  • In some cases it is necessary to connect/login the user to a provider? prior to calling the API method. You can learn more in the Social Login guide.

 

In the Publish newsfeed stories you will find a complete working example that uses the socialize.publishUserAction method. You may view the code, run it and view the outcome.

Page statistics
1846 view(s) and 4 edit(s)
Social share
Share this page?

Tags

This page has no custom tags.
This page has no classifications.

Comments

You must to post a comment.

Attachments