|
|
|
|
Publish Newsfeed - AdvancedFrom $1Table of contentsSee it in action
Check out the code
<html>
<head>
<title>Gigya Socialize Demo - Publish User Action</title>
<style>
body {font-family:Arial;font-size: 12px; background-color:#fff; line-height:20px}
</style>
<SCRIPT type="text/javascript" lang="javascript"
src="http://cdn.gigya.com/JS/socialize.js?apikey=2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N"></SCRIPT>
<script>
// Configuration Object
var conf =
{
APIKey: '2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N'
};
// 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 image1 = {
src: 'http://www.infozoom.ru/wp-content/uploads/2009/08/d06_19748631.jpg',
href: 'http://www.infozoom.ru',
type: 'image'
}
var image2 = {
src: 'http://www.cherrybam.com/graphics/graphics-cute/cute004.gif',
href: 'http://www.cherrybam.com/',
type: 'image'
}
var swf = {
src: 'http://widgets.funny4myspace.com/widgets/pickup/randompick.swf',
width: '800',
height: '400',
previewImageURL: 'http://funny4myspace.com/widgets/pickup/thumbnail.gif',
previewImageWidth: '200',
previewImageHeight: '90',
type: 'flash'
}
var mp3 = {
type: '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'
}
function onLoad()
{
// get user info
gigya.services.socialize.getUserInfo(conf,{callback:renderUI});
// register for connect status changes
gigya.services.socialize.addEventHandlers(conf,
{ onConnect: renderUI, onDisconnect: renderUI});
}
</script>
<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.services.socialize.UserAction();
// Setting the User Message
act.setUserMessage("This is a newsfeed publish test. This is the user message");
// Setting the Title
act.setTitle("This is my title");
// Setting Link Back
act.setLinkBack("http://bit.ly/5MFb2V");
// Setting Description
act.setDescription("This is my Description.");
// Adding Action Links
act.addActionLink("Contact", "http://bit.ly/cFF64");
// Add Media (Media type depends on the checked radio-button)
if (document.getElementById("Image").checked) {
// Add two images
act.addMediaItem(image1);
act.addMediaItem(image2);
}
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.services.socialize.publishUserAction(conf, 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>
</head>
<body onload="onLoad()">
<b>Step 1: Connect</b>
<div id="divConnect"></div>
<script type="text/javascript">
// show connect UI in "divConnect"
gigya.services.socialize.showConnectUI(conf, {
width: 190,
showTermsLink: 'false', // remove 'terms' link
hideGigyaLink: 'true', // remove 'Gigya' link
useFacebookConnect: 'true', // use Facebook connect when connecting to Facebook
containerID: "divConnect" // The component will embed itself inside the divConnect Div
});
</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>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="693"
height="579" applicationComplete="init()"
fontFamily="Arial" fontSize="12" backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#FFFFFF, #FFFFFF]">
<mx:Canvas x="29" y="57" id="connectCanvas" width="325" height="103">
</mx:Canvas>
<mx:Label x="29" y="31" text="Step 1: Connect" width="113" color="#6E6E6E"
fontWeight="bold" fontSize="12" fontFamily="Arial"/>
<mx:Label x="29" y="194" text="Step 2: Select Media Type" color="#6E6E6E"
fontWeight="bold" fontFamily="Arial" fontSize="12"/>
<mx:RadioButtonGroup id="radiogroup1"/>
<mx:RadioButton id="btnImage" x="36" y="223" label="Image" groupName="radiogroup1"/>
<mx:RadioButton id="btnVideo" x="36" y="249" label="Video" groupName="radiogroup1"/>
<mx:RadioButton id="btnMp3" x="36" y="275" label="Mp3" groupName="radiogroup1"/>
<mx:RadioButton id="btnFlash" x="36" y="301" label="Flash" groupName="radiogroup1"/>
<mx:Label x="29" y="356" text="Step 3: Post Newsfeed item" color="#6E6E6E"
fontWeight="bold" fontFamily="Arial" fontSize="12"/>
<mx:Label x="29" y="382" width="352" fontFamily="Arial">
<mx:text>Click the button below to post a Newsfeed item</mx:text>
</mx:Label>
<mx:Button id="btnPublishAction" x="29" y="408" label="Post" width="94" enabled="false"
click="publishAction()"/>
<mx:Label id="status" x="29" y="453" width="134"/>
<mx:Script>
<![CDATA[
// Define a configuration object. Insert your Gigya APIKey below:
private var conf:Object = {
APIKey: '2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N'
}
// Media Objects
private var video:Object = {
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'
}
private var image1:Object = {
src: 'http://www.infozoom.ru/wp-content/uploads/2009/08/d06_19748631.jpg',
href: 'http://www.infozoom.ru',
type: 'image'
}
private var image2:Object = {
src: 'http://www.cherrybam.com/graphics/graphics-cute/cute004.gif',
href: 'http://www.cherrybam.com/',
type: 'image'
}
private var swf:Object = {
src: 'http://widgets.funny4myspace.com/widgets/pickup/randompick.swf',
width: '800',
height: '400',
previewImageURL: 'http://funny4myspace.com/widgets/pickup/thumbnail.gif',
previewImageWidth: '200',
previewImageHeight: '90',
type: 'flash'
}
private var mp3:Object = {
type: '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'
}
// This method is executed on applicationComplete
private function init():void {
// Initialize the "mcRoot" attribute of the conf object -
// should refer to the root of the flash container.
this.conf.mcRoot=this.root;
// Load socialize service
// Create the load-parameters object
var loadParams:Object = {
services:'socialize',
callback:onGigyaInit
}
// Load the services
gigya.load(conf,loadParams);
}
// Wait for the load to complete and handle failures/success
private function onGigyaInit(response:*):void {
if (response.hadError) {
// handle failure
trace('An error has occurred while attempting to load Socialize service');
} else {
// get user info
gigya.services.socialize.getUserInfo(conf,{callback:renderUI});
// register for connect status changes
gigya.services.socialize.addEventHandlers(conf,
{ onConnect:renderUI, onDisconnect:renderUI } );
showConnectUI();
}
}
private function renderUI(res:Object): void {
// enable/disable "Post" button
btnPublishAction.enabled = (res.user!=null && res.user.isConnected);
}
// show connect UI in connectCanvas
private function showConnectUI(): void {
//Define parameters object:
var params:Object=
{
width: 190,
useFacebookConnect: true,
showTermsLink: 'false',
hideGigyaLink: 'true',
container: connectCanvas // The Widget will be embedded
// inside the connectCanvas
}
// Calling the Socialize API method - connect:
gigya.services.socialize.showConnectUI(conf, params);
}
// Create and Publish User's Action
// This method is associated with the "btnPublishAction" click
private function publishAction():void
{
// Constructing a UserAction Object;
// Constructor receives an Action Template string
var act:Object =
new gigya.services.socialize.UserAction();
// Setting the User Message
act.setUserMessage("This is a newsfeed publish test. This is the user message");
// Setting the Title
act.setTitle("This is my title");
// Setting Link Back
act.setLinkBack("http://bit.ly/5MFb2V");
// Setting Description
act.setDescription("This is my Description.");
// Adding Action Links
act.addActionLink("Contact", "http://bit.ly/cFF64");
// Add Media (Media type depends on the checked radio-button)
switch (radiogroup1.selectedValue) {
case "Image":
// Add two images
act.addMediaItem(image1);
act.addMediaItem(image2);
break;
case "Video":
// Add a video
act.addMediaItem(video);
break;
case "Mp3":
// Add mp3 audio
act.addMediaItem(mp3);
break;
case "Flash":
// Add a Flash file
act.addMediaItem(swf);
break;
}
// Parameters for the publishUserAction method, including the UserAction object
var params:Object =
{
userAction:act,
callback:publishAction_callback
};
// Publish the User Action
gigya.services.socialize.publishUserAction(conf, params);
}
// Display a status message according to the response from publishUserAction.
private function publishAction_callback(response:Object):void
{
switch (response.errorCode)
{
case 0:
status.setStyle("color","#47B838");
status.text = "Newsfeed item sent.";
break;
default:
status.setStyle("color","#F91403");
status.text = "Unable to send newsfeed item. status="
+ response.errorCode + "; " + response.errorMessage;
}
}
]]>
</mx:Script>
</mx:Application>
Note: In order to make this code work in your environment, please:
Tags:
|
||||
|