blog
Facebook PublishPost with image (update) at Jozef Chúťka's blog
November 23, 2009
ActionLinkData Facebook facebook api FacebookCall PublishPost PublishUserAction
Facebook PublishPost with image (update)

Soon, facebook api method PublishUserAction (flash api method) gets deprecated (December 20, 2009). It is suggested to use Facebook.streamPublish instead, and you can find this method in facebook flash api as PublishPost method. If you have problems to make it work take a look at the next simple example that is using image attachment and actionLinkData (as prelink anywhere).
Working part of application:
var message:String = "Hallo world";
var attachment:Object = {media: [{
type: "image",
src: "http://www.somedomain.com/someimage.jpg",
href: "http://www.somedomain.com/sometarget.html"
}]};
var actionLinkData:ActionLinkData = new ActionLinkData();
actionLinkData.href = "http://www.someapplication.com/sometarget.html";
actionLinkData.text = "Uber application";
var post:PublishPost = new PublishPost(message, attachment, [actionLinkData], fbook.uid);
var call:FacebookCall = fbook.post(post);Update (Feb 12, 2009): Type-proper usage:
import com.facebook.commands.stream.PublishPost;
import com.facebook.data.stream.ActionLinkData;
import com.facebook.data.stream.AttachmentData;
import com.facebook.data.stream.MediaTypes;
import com.facebook.data.stream.StreamMediaData;
var message:String = "Some status message"; // can be empty
var media:StreamMediaData = new StreamMediaData();
media.type = MediaTypes.PHOTO;
// MediaTypes defines "link", "video", "photo" but
// you should use "image", "flash", or "mp3"
// http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
media.src = "http://www.somedomain.com/someimage.jpg";
media.href = "http://www.somedomain.com/go/somewhere.html";
var attachment:AttachmentData = new AttachmentData();
attachment.media = [media];
attachment.href = "http://www.somedomain.com/go/somewhere.html";
attachment.name = "Image title";
attachment.caption = "Some subtitle";
attachment.description = "Lorem Ipsum text about your image";
var link:ActionLinkData = new ActionLinkData();
link.href = "http://www.somedomain.com/your_application.html";
link.text = "Your application name";
var post:PublishPost = new PublishPost(message, attachment, [link], facebook.uid);Read more about Stream.publish and Attachment (Streams)
By default, the photo and the Flash object are rendered in a space up to 90 pixels in both height or width, with an emphasis on scaling the image to be 90 pixels wide (90×90 px max).
You may Leave a comment or Subscribe to Comments RSS or Trackback this entry.
54 comments so far
Matthew November 4, 2010 13:33 Hey Jozef, Once again, best place on the net for answer in this respect 🙂 Got it working like this: var _actionLinks:Object=new Object(); _actionLinks = {name:”Name of Link”,link:”http://somthing”}; } //Has Permissions, Post automatically: Facebook.postData ( _method, publishPostResult, { message:”Actual Message”, name:”Title”, link:”http://…”, source:”Image.jpg”, caption:”capion”, actions:JSON.encode(_actionLinks) } ); Wouldn’t of gotten there without Your help, Thank You 😀
Jozef Chúťka November 4, 2010 13:52 @Matthew, thank you it seems like there has been some changes, its good to have it listed here: previously data.attachment.properties vs. now data.actions
filippo December 16, 2010 13:10 Hi Jozef, how are you? I have a question for you about f-book. For the moment I have suspended the project of the depth map, I will go back on that later. I have to post a swf file in the wall including a title and a short message. I have set the permissions during the session login: “read_stream,publish_stream,user_photo_video_tags,friends_photo_video_tags,user_photos,friends_photos,email,manage_pages,friends_about_me,user_about_me,read_friendlists,user_videos” I try making a request like this: var parameters:Object = new Object(); parameters.message = “bla bla bla…”; parameters.actions = {“name”:”View”,”link”:http://www.zo….”}; parameters.source = {“file.swf”}; var fql:String = “/”+12345+”/feed”; Facebook.api(fql,handleFeedback,parameters,”POST”); At the end nothing as I wanted. Do you have any suggestion? Thk 😉 Cheers, Filippo
Jozef Chúťka December 16, 2010 16:34 Hi filippo, I recomend you to switch to FacebookOAuthGraph library: http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/ in that case you can use an example from http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/ (see “Publish feed with flash”)
Leave a comment
Please be polite and on topic. Your e-mail will never be published.
Jozef Chúťka — 2010-10-05: Hi Matthew, I recoomend you to switch to FacebookOAuthGraph http://blog.yoz.sk/facebookoauthgraph/ You can open the permission window using ExternalInterface and javascript
eternity — 2010-10-23: I am getting error while publishing the post in facebook.
eternity — 2010-10-23: From as3 how to publish the post? i’m getting the error like uid or sessionid is required. if i pass the uid, i am getting the error as user has not authorised the application. How to rectify it? Can anyone help me?
Jozef Chúťka — 2010-10-25: @eternity, first you need to get authorized, please read article http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/
Matthew — 2010-11-04: Hi Jozef, Concering the Graph method of posting, I see fb has added support for actionLinks: http://developers.facebook.com/blog/post/420. Our publishing worked great before using Flash Builder 4, Facebook Graph AS3 API and the following syntax: Code: Facebook.postData ( _method, publishPostResult, { message:_messageObject.message, name:_messageObject.attachment.name, link:_messageObject.attachment.href, source:_messageObject.attachment.media.src, caption:_messageObject.attachment.caption } ); So I have tried adding action links using: Code: Facebook.postData ( _method, publishPostResult, { message:_messageObject.message, name:_messageObject.attachment.name, link:_messageObject.attachment.href, source:_messageObject.attachment.media.src, caption:_messageObject.attachment.caption, actions:{name:_messageObject.action_links.text, link:_messageObject.action_links.href} } ); and numerous other ways. but i keep getting the following error: OAuth “Facebook Platform” “invalid_request” “(#100) actions should be a JSON-encoded dictionary with \”name\” and \”link\” keys” Any help would be greatly appreciated.
Jozef Chúťka — 2010-11-04: Hi Matthew, action links works like this: attachment.properties = {prop1:{text: “value 1″, href:”http://”}, prop2:…}; data.attachment = JSON.encode(attachment); for more read http://blog.yoz.sk/2010/06/extending-facebookoauthgraph-class/