June 7, 2010 - No Comments!

Posting to Social Media – An Actionscript Perspective

As more clients understand and appreciate the contribution social media has to the success of their projects, it is becoming ever more a standard for the projects I undertake to include some form of share functionality. Some of you are probably aware of the early issues faced with 3rd party APIs when using them within the Actionscript side of the project, as opposed to the javascript of the the holding page.

Lets start with the more simple side of things where users simply want to share a simple link.



Add to Any

Those are just some of the basics. For a slightly different scenario, how about we have created a project where the user wishes to share a custom status alongside an image for example. You will see examples of this in your "News Feed" of your Facebook Account where friends may have shared games scores which also contain a link to the game and a small thumbnail image to promote the game or application.

Facebook API
In recent months the Facebook API has evolved into something a lot easier to follow and implement. The simplest and quickest way to get up to speed on the basics of the API is to follow the starter guides on Adobe's Devnet.

In order to post these more detailed status reports we need to seek out extended permissions. If we were using the earlier API in Flash we would need to keep switching in and out of Flash till all the required permissions had been granted. Luckily now, this is no longer the case. By using Facebook Connect we are able to allow javascript to handle all of these processes in one gentle sweep.

In my test case once the session has been created I simply make a 2nd external call for extended permissions which requests the permissions I am seeking. All authentication is carried out in one gentle swoop by the Facebook API is nicely designed overlay and a notification is sent back.

So for the AS3, we start by jumping into the start of our session.

protected function onConnect(event:FacebookEvent):void{
var call:FacebookCall=fbook.post(new GetInfo([sessionData.uid],[GetInfoFieldValues.ALL_VALUES]));
call.addEventListener(FacebookEvent.COMPLETE, onGetInfo);
Alert.show("Error connecting to Facebook","Error");

Once we have connected we gain access to the user's profile. From here we need to check if we have the required extended permissions to post what we shall call our detailed status. To do this we create a call with a parameter of a HasAppPermission, to this call we add our listener for once the call has been completed which in turn is handled buy our onPermissionInfo handler.

protected function onGetInfo(event:FacebookEvent):void
user=(event.data as GetInfoData).userCollection.getItemAt(0) as FacebookUser;// Check for permissions
var call:FacebookCall = fbook.post(new HasAppPermission(ExtendedPermissionValues.STATUS_UPDATE, sessionData.uid));
call.addEventListener(FacebookEvent.COMPLETE, onPermissionInfo);
Alert.show("Error getting Facebook user data","Error");

Once this process has completed, our return values will tell us if we have the required rights or not, if not we make a call to the fbExtendedPermission method embedded within the html of our holding page. The idea behind this structure is that we have an automated process. Each time a permission change is processed the onPermissionChange will be called and allowing our application to act upon the outcome.

protected function onPermissionInfo(event:FacebookEvent):void
if ( event.success && ( event.data as BooleanResultData ).value )

function fbExtendedPermission()
"publish_stream", // permission name(s)
flashContent.onPermissionChange, // response callback
true); // enable profile selector (only for "publish_stream")

Now this is just a simple example of handling extended user rights in one simple process, depending on the requirements of your project you may be required to seek different rights from the user's facebook account, this is just a small example based on what I find to be the most common of my clients requirements.

Published by: nick in AS3, Flash, Flex

Leave a Reply