Publish Newsfeed - Advanced Demo

Skip to end of metadata
Go to start of metadata

 

See it in Action

  Step 1: Connect

Step 2: Select Media Type
Image
Video
Mp3
Flash

Step 3: Post Newsfeed item
Click the button below to post a Newsfeed item

 

Read More

The UserAction Object

API Reference

Check Out the Code

 

<html>
<head>
    <title>Gigya Demo  - Publish User Action</title>
    <style>
     body {font-family:Arial;font-size: 12px; background-color:#fff; line-height:20px}
    </style>
</head>
</body>
    <SCRIPT type="text/javascript" lang="javascript"
       src="https://cdns.gigya.com/JS/gigya.js?apikey=3_mK2cmEzLkzhqe4MUrtPncxbv4wKsYAhsew0iVwhVUls3c_Jx_HLX434jAVpq5M_W"></SCRIPT>
    <script>
	<script>
	    // Media Objects
        var video = {
            src: 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1',
            previewImageURL: 'http://graphics8.nytimes.com/images/2006/01/02/science/03cute.large2.jpg',
            type: 'flash'
        }
        var image = {
            src: 'http://www.infozoom.ru/wp-content/uploads/2009/08/d06_19748631.jpg',
            href: 'http://www.infozoom.ru',
            type: 'image'
        }
        var swf = {
            src: 'http://dagobah.net/flash/Tic_Tac_Toe.swf',
            width: '800',
            height: '400',
            previewImageURL: 'http://0.tqn.com/d/boardgames/1/G/N/q/tic_tac_toe_200.jpg',
            previewImageWidth: '200',
            previewImageHeight: '90',
            type: 'flash'
        }
        var mp3 = {
            src: 'http://www.looptvandfilm.com/blog/Radiohead%20-%20In%20Rainbows/01%20-%20Radiohead%20-%2015%20Step.MP3',
            title: '15 Step',
            artist: 'Radiohead',
            album: 'In Rainbows',
            type: 'mp3'
        }
       
        function onLoad()
        {
            // get user info
            gigya.socialize.getUserInfo({callback:renderUI});	    
            
            // register for connect status changes
            gigya.socialize.addEventHandlers({ onConnectionAdded: renderUI, onConnectionRemoved: renderUI });
            
        }

		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();
		    
		    // Setting the Title and subtitle
		    act.setTitle("This is my title");
		    act.setSubtitle("This is my subtitle");
		    // Setting Link Back
		    act.setLinkBack("http://bit.ly/5MFb2V");
		    // Setting Description
		    act.setDescription("This is my Description.");
		    // Adding Action Links
		    act.addActionLink("Read More", "http://bit.ly/cFF64");  
		    // Add Media (Media type depends on the checked radio-button)
		    if (document.getElementById("Image").checked) {
		        // Add image
		        act.addMediaItem(image);
		    }
		    if (document.getElementById("Video").checked) {
		        // Add a video
		        act.addMediaItem(video);
		    }
		    if (document.getElementById("Mp3").checked) {
		        // Add mp3 audio
		        act.addMediaItem(mp3);
		    }
		    if (document.getElementById("Flash").checked) {
		        // Add a Flash file
		        act.addMediaItem(swf);
		    }
		    // Parameters for the publishUserAction	method, including the UserAction object
			var params = 
			{
			    userAction:act,
			    callback:publishAction_callback
			};
			
            // Publish the User Action
			gigya.socialize.publishUserAction(params);
		}
		// 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.";
					break;
				default:
					document.getElementById('status').style.color = "red";
					document.getElementById('status').innerHTML = 
							"Unable to send newsfeed item. Error Code:" 
					        + response.errorCode + "; " + response.errorMessage;
			}
		}
    </script>
	<b>Step 1: Connect</b>
	<div id="divConnect"></div>
        <script type="text/javascript">
	        // show 'Add Connections' Plugin in "divConnect"
	        gigya.socialize.showAddConnectionsUI({ 
				height:65
				,width:175
				,showTermsLink:false // remove 'Terms' link
                , disabledProviders: "yahoo"//yahoo does not suppor sharing
				, containerID: 'divConnect' // The component will embed itself inside the divConnect Div
				, shortURLs: 'never'
			});
        </script>    
    <br />
    <b>Step 2: Select Media Type</b>
    <form>
    <input type=radio id="Image" name="mediaType" value="Image">Image<br />
    <input type=radio id="Video" name="mediaType" value="Video">Video<br />
    <input type=radio id="Mp3" name="mediaType" value="Mp3">Mp3<br />
    <input type=radio id="Flash" name="mediaType" value="Flash">Flash<br />
    </form>
    <br />
    <b>Step 3: 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>
</body>
</html>

Notes:

In order to make the above code work in your environment, please note:

  • 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 from 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.
  • If you are using https, be sure to further adjust the js API url to: https://cdns.gigya.com/JS/gigya.js?apikey=<Your_API_Key>.