socialize.publishUserAction JS

Skip to end of metadata
Go to start of metadata

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 Advanced Sharing.

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

 

 

Parameters

The following table lists the available parameters:

RequiredNameTypeDescription

userAction

UserAction objectThe user action to publish.
Notes: 
  • A shared URL must match the  approved URLs (domains) f or the specified API key, otherwise the share will not work. 
  • When Twitter is the provider, only the Title and Link Back are posted.
actionAttributesJSON objectIn 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>" }

 
callbackfunction
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.
cidstring
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.

contextobject
A developer-created object that is passed back unchanged to the application as one of the fields in the response object.
disabledProvidersstring
A comma-delimited list of provider names to exclude in the method execution. This parameter gives the possibility to specify providers to which you do not 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 Twitter, define: disabledProviders: "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.

enabledProvidersstring
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 Twitter, define: enabledProviders: "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.

shortURLsstring
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 users of the US data center.
    • shr.gs for users of the European data center.
    • vst.to for users of the Australian data center.
    • socli.ru for users of the Russian data center.
    • s.gigya-api.cn for users of the Chinese data center.
  • 'whenRequired': URLs longer than 139 characters are shortened in accordance with provider preferences.
  • 'never' - never shorten URLs. Where providers permit, URLs are left untouched.

To determine your data center see Finding Your Data Center.


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:

ProviderNote
FacebookN/A
TwitterN/A
LinkedInShortened URL is posted to the social network but traffic reports show abbreviated URL (e.g., http://developers.gigya.com/display/GD/showShareBarUI+JS is abbreviated to developers.gigya.com).
MicrosoftNot for share. (Note: messenger has been replaced by microsoft, however, for backward compatibility, either can be used).
DeliciousShortened URL is posted to the social network but traffic reports show abbreviated URL (e.g., http://developers.gigya.com/display/GD/showShareBarUI+JS is abbreviated to developers.gigya.com).
WhatsAppOnly on mobile.
RedditN/A
GooglePlusN/A
Google BookmarksN/A
VKontakteN/A
nk.plN/A
XingN/A
TuentiN/A
HatenaN/A
PinterestShortened URL is posted to the social network but traffic reports show abbreviated URL (e.g., http://developers.gigya.com/display/GD/showShareBarUI+JS is abbreviated to developers.gigya.com).
BaiduN/A
FriendFeedN/A
TumblrN/A
SinaN/A
mixiN/A

When Gigya's URL shortening service is active, Gigya tracks all the traffic coming from the distributed URLs. In such case, 'Referred Traffic' reports will 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.

tagsstringA comma separated list of tags that are used to identify the share operation.
UserActionUserAction objectIt 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: (i.e. facebook, twitter, etc.) followed by "UserAction". For example: twitter UserAction - 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 UserAction specifies the content to be used for the specific network.
userLocationJSON ObjectThe 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.

 

Response Object Data Members

FieldTypeDescription
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 table.
errorMessage string A short textual description of an error associated with the errorCode for logging purposes.
callId string Unique identifier of the transaction, for debugging purposes.
context object The context object passed by the application as a parameter to the API method, or null if no context object has been passed.
providerPostIDsarrayAn 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 gigya.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.