Feb 10, 2010

Publish post to facebook Wall (News feeds) from actionscript

This article shows two ways how to make publish to stream Wall (News feeds) from flash facebook application or game:

  • Publish post to stream with no user actions (using Stream.publish)
  • Publish to stream from rendered Feed form (using Facebook.streamPublish)

1. Publish to stream using Stream.publish method

You can find detailed description of this method here http://wiki.developers.facebook.com/index.php/Stream.publish

That is very detailed description and I only want to show how to use it from actionscript 3.
Most probably you use actionscript facebook API client libraries from here.
When I have found description of Sream.publish method on page above and understood that I need to use it (without feed form rendering) I couldn't find any appropriate actionscript method in documentation. Only digging of client library source code helped me to find PublishPost class that allows calling Stream.publish method.

Here is example how to use this method from actionscript 3:

private function publishToStream():void{
var message:String = "Stream.publish example";
var attachment:Object = {media: [{
type: "image",
src: "http://novacoders.com/design/img/logo.gif",
href: "http://novacoders.com/"
}]};
var actionLinkData:ActionLinkData = new ActionLinkData();
actionLinkData.href = "http://novacoders.com/services/flashdevelopment/";
actionLinkData.text = "Flash games development";
var post:PublishPost = new PublishPost(message, attachment, [actionLinkData], fbook.uid);
post.addEventListener(FacebookEvent.COMPLETE, onPublish);
var call:FacebookCall = fbook.post(post);
}

private function onPublish(e:FacebookEvent):void{
if(e.error!=null){
// fbook.grantExtendedPermission("publish_stream");
trace("Publish to stream: " + e.error.errorMsg);
}else{
trace("Publish to stream: onPublish " + e.data);
}
}


2. Publish to stream from feed form using Facebook.streamPublish method

to be continued