Publish Newsfeed - Basic

Last modified 08:03, 11 Nov 2014

See it in Action

Check Out the Code

    <title>Gigya Socialize Demo  - Publish User Action</title>
	 body {font-family:Arial;font-size: 12px; background-color:#fff; line-height:20px}
	<SCRIPT type="text/javascript" lang="javascript" 
        function onLoad()
            // get user info
            // register for connect status changes
            gigya.socialize.addEventHandlers({ onConnectionAdded: renderUI, onConnectionRemoved: renderUI }); 

	<script type="text/javascript">

		function renderUI(res)
		    document.getElementById('btnPublishAction').disabled = 
					(res.user == null || !res.user.isConnected);		    

		// Create and Publish User's Action
		// This method is associated with the "btnPublishAction" click
		function publishAction() {

		    // Constructing a UserAction Object
		    var act = new gigya.socialize.UserAction();
		    // Adding Action Link
		    act.addActionLink("Watch the movie", 
			// Setting the Title and subtitle

            act.setTitle("This is my title");

            act.setSubtitle("This is my subtitle");

            // Setting Link Back


			act.setUserMessage("This is my message to you");
		    // Parameters for the publishUserAction method, 
			// including the UserAction object
			var params = 
            // Publish the User Action


		// Display a status message according to the response from publishUserAction.
		function publishAction_callback(response)
			switch (response.errorCode )
				case 0:
					document.getElementById('status').style.color = "green";
					document.getElementById('status').innerHTML = "Newsfeed item sent.";
					document.getElementById('status').style.color = "red";
					document.getElementById('status').innerHTML = 
							"Unable to send newsfeed item. Error Code:" 
					        + response.errorCode + "; " + response.errorMessage;

<body onload="onLoad()">
	<b>Step 1: Connect</b>
	<div id="divConnect"></div>
        <script type="text/javascript">
	        // show 'Add Connections' Plugin in "divConnect"
				, width:175
				, showTermsLink:false // remove 'Terms' link
				, hideGigyaLink: true // remove 'Gigya' link
                , disabledProviders: "yahoo" //Yahoo does not support sharing
				, containerID: "divConnect" // The component will embed itself inside the divConnect Div 

    <br />
    <br />
    <b>Step 2: Post Newsfeed item</b><br />
    Click the button below to post a Newsfeed item<br />
    <input type=button id="btnPublishAction" onclick="javascript:publishAction()" value="Post" />
    <div id="status"></div>

In order to make this code work in your environment, please:
  • Click the "view source" icon (link located above code on the right hand side) - This will open a popup window with a text version of the code, which you may copy.
  • The API key in the sample will only work on http://localhost/...
  • To load the page from your domain, modify the value of the "APIKey" field in the code to your own Gigya API Key. 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.

Page statistics
640 view(s) and 2 edit(s)
Social share
Share this page?


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


You must to post a comment.