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

11 comments:

  1. would you please show the full fla or as file? i lose the part of
    var call:FacebookCall = fbook.post(post); <<

    thanks a lot

    ReplyDelete
  2. The user hasn't authorized the application to perform this action is what im getting from the else statement inside onPublish. What am I doing wrong. Thanx. Johan.

    ReplyDelete
  3. Great post, thanks! How did you figure out the structure of the "attachment" parameter?

    ReplyDelete
  4. I get this error

    Publish to stream: The user hasn't authorized the application to perform this action

    what can i do?? please can you help me

    thanks

    ReplyDelete
  5. Can't wait for the second part:
    Publish to stream from feed form using Facebook.streamPublish method

    ReplyDelete
  6. Hi there!

    Maybe you can help me with the permissions thing.
    I get an error every time I run this code: "Publish to stream: The user hasn't authorized the application to perform this action".
    I make fbook.grantExtendedPermission("publish_stream"); Facebook told that "You have already granted permissions to this application."
    However, this error still appears. Thanks.

    ReplyDelete
  7. Thanks a lot dude!

    ReplyDelete
  8. you ever gonna do the feed form option?

    ReplyDelete
  9. Seriously? #2 is exactly what I need....!

    ReplyDelete
  10. Thanks for posting this, it's hard to find information on how to do this (except of course for using php etc).

    ReplyDelete