Description
Publishes a user action to the newsfeed of all the connected providers which support this feature.
To learn more about publishing newsfeeds, 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
This operation is currently supported by the following providers: Facebook, Myspace, Twitter, Yahoo, LinkedIn.
Syntax
gigya.services.socialize.publishUserAction(conf,params)
Method parameters
conf object
Please refer to the Conf object page for full specifications.
params object members
| Required | Name | Type | Description |
| Required | userAction | UserAction object | The user action to publish. |
| Optional | callback | function | A reference to a callback function. Gigya will call 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 which is passed to the callback function. |
| enabledProviders | string | A comma delimited list of provider names to include in the method execution. This parameter gives the possibility to apply this method to only 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 provides).
For example, if you would like the method to apply only to Facebook and Twitter, define: enabledProviders="facebook,twitter".
Note: the value of this parameter overrides the value of the identical parameter in the Conf object.
Valid provider names include: 'facebook', 'myspace', 'twitter', 'yahoo', 'linkedin'. |
| | disabledProviders | string | A comma delimited list of provider names to exclude in the method execution. This parameter gives the possibility to specify provides that you don't want this method to apply to. If you do not set this parameter, by default, no provider is disabled (i.e. the method applies to all connected provides).
For example, if you would like the method to apply to all providers except Google and Twitter, define: disabledProviders="google,twitter".
Note: the value of this parameter overrides the value of the identical parameter in the Conf object.
Valid provider names include: 'facebook', 'myspace', 'twitter', 'yahoo', 'linkedin'. |
| | cid | string | A string of maximum 100 characters length. This string will be associated with each transaction and will later appear on 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. The "Context ID" combo box lets you filter the report data by site/application context.
Note: the value of this parameter overrides the value of the identical parameter in the Conf object. |
| | shortURLs | string | Using this parameter you may determine whether to use Gigya's URL shortening service for URLs, which are published through this method. The optional values for this parameter are: - 'always' (default): always shorten URLs.
- 'whenRequired': shorten URLs when needed - when posting to Twitter, LinkedIn, MySpace and Yahoo where the status update is limited to 140 char.
- 'never' - never shorten URLs.
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: the value of this parameter overrides the value of the identical parameter in the Conf object. |
| | context | object | A developer-created object that will be passed back unchanged to the application as one of the fields in the response object. |
| | scope | string | This parameter is relevant only if you are integrating the Newsfeed Widget in your site. When publishing feed items, by default - the feed items are published to social networks only and will not appear on the site's Newsfeed Widget. 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 Newsfeed Widget.
- '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 Newsfeed Widget).
- '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 Newsfeed Widget.
|
| | privacy | string | This parameter is relevant only if you are integrating the Newsfeed Widget in your site. The privacy level determines how the user action is presented in each of the Newsfeed Widget 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 user name and image) in the 'Friends' tab
|
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. |
Code Sample
var conf = {
APIKey:'Put Your APIKey here'
};
// Constructing a UserAction Object
var act = new gigya.services.socialize.UserAction();
act.setUserMessage("This is the user message"); // Setting the User Message
act.setTitle("This is my title"); // Setting the Title
act.setLinkBack("http://www.gigya.com/site/content/socialize.aspx"); // Setting the Link Back
act.setDescription("This is my Description"); // Setting Description
act.addActionLink("Read More", "http://www.gigya.com/site/content/socialize.aspx"); // Adding Action Link
// Adding a Media (image)
act.addMediaItem( { type: 'image', src: 'http://gigya.com/site/images/bsAPI/gs_logo.jpg', href: 'http://www.gigya.com/site/content/socialize.aspx' });
var params =
{
userAction:act
};
// Publishing the User Action
gigya.services.socialize.publishUserAction(conf, params);
function publishUserAction():void {
var conf:Object = {
mcRoot:this.root,
APIKey:'Put Your APIKey here'
};
// Constructing a UserAction Object
var act:Object = new gigya.services.socialize.UserAction();
act.setUserMessage("This is the user message"); // Setting the User Message
act.setTitle("This is my title"); // Setting the Title
act.setLinkBack("http://www.gigya.com/site/content/socialize.aspx"); // Setting the Link Back
act.setDescription("This is my Description"); // Setting Description
act.addActionLink("Read More", "http://www.gigya.com/site/content/socialize.aspx"); // Adding Action Link
// Adding a Media (image)
act.addMediaItem( { type: 'image', src: 'http://gigya.com/site/images/bsAPI/gs_logo.jpg', href: 'http://www.gigya.com/site/content/socialize.aspx' });
var params:Object =
{
userAction:act
};
// Publishing the User Action
gigya.services.socialize.publishUserAction(conf, 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.
- The API key in the sample will only work on http://localhost/...
- To run the code on your own domain, modify the API key in the example to your own API key. A Gigya API Key can be obtained on the Site Setup page on Gigya's website. Please make sure that the domain you are loading the page from is the same domain name that you used for generating the API Key.
- In some cases it is necessary to connect the user to a provider? prior to calling the API method. For connecting the user to a provider, you may use the Connect API method call or the pre-built Connect Widget.
- Best practice is, to define one global conf object and use it throughout the application.
In "Publish newsfeed stories" you will find a complete working example which uses socialize.publishUserAction method. You may view the code, run it and view the outcome.