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).

Thanks, very helpfull post
That’s cool!unfortunately I can’t make it work: when I send the PublishPost everything seems work, but then I debug it and see a error code 200 (The application does not have permission to perform this action.). Any ideas how to fix this? Can you post the complete code?
Hi, error code 200 may be caused by insufficient permissions. Your app needs publish_stream permission, check out this post http://blog.yoz.sk/2009/10/fb-connect-showpermissiondialog/
I have some errors with this line : var post:PublishPost = new PublishPost(message, attachment, [actionLinkData], fbook.uid);
Error 1067 : Contrainte implicite d’une valeur du type Array vers un type sans rapport com.facebook.data.feed:TemplateData.
Error 1067 : Contrainte implicite d’une valeur du type String vers un type sans rapport com.facebook.data.feed:ActionLinkCollection.
Error 1118: Contrainte implicite d’une valeur du type statique Object vers un type peut-être sans rapport String.
I have a Facebook app with an iframe and I would like to publish post on user’s wall.
Please help me !!
Hi Poudib, do you use the latest facebook flex api? which version do you use?
This is great thanks very much. Took me a bit to get it to work, but it fails silently when using ‘media.type = MediaTypes.PHOTO;’ if you use ‘media.type = “image”‘ it works fine.
Hi, great example.
do you know if it is posible to get the extented persmisions when calling from a remote site, and not at site embeded in the facebook page?
Hi Tommy,
extended permissions comes with facebook application instance, no matter whether it is web or desktop application type. Once your user grants permissions to your app, you have it. You can have your app both embedded in facebook and in your site at once, see:
http://onboard.yoz.sk/ vs. http://apps.facebook.com/onboard_yoz_sk/ (embedded)
…before your app can use something from facebook api, you must support facebook connection (main facebook flash client does it in new window)…
for extended permissions read these:
http://blog.yoz.sk/2010/01/facebook-extended-permissions-with-authorization-by-overriding-class-in-swc/
http://blog.yoz.sk/2010/01/elegant-facebook-login-for-desktop-application/
good luck
Sorry, while posting I have an 210 error. Do anyone know what is it?
And what can I do? All permissions are granted…
mb smth in app settings?
hi CorC, try using
media.type = “image”
Thanks for this very enlightening seeing as the PublishPost is not mentioned anywhere in the online documents.
hi thanks for the snippet
i am posting the message
is show succesful in call.addEventListener(FacebookEvent.COMPLETE,onComplete)
event
but am not able to see my posted message in facebook site
@girish if complete event was dispatched your message should have been posted, keep refreshing facebook – it sounds like a facebook issue
Jozef,
First of all, thanks for the blog. This blog is literally the only source of really solid, reliable, trustworthy information I can find for making Flash games that interface with Facebook. Keep it coming, your stuff is fantastic.
I am struggling with making a Flash app do feed posts. I believe that you’re incorrect when you say that the AS3 API command “com.facebook.commands.stream.PublishPost” is an exact analog for the FBJS API method “streamPublish”: http://developers.facebook.com/docs/fbjs/streamPublish
…Because the streamPublish method appears to NOT require the publish_stream extended permission! …Whereas, as you note above, this permission IS required by the PublishPost command in AS3 (which I believe is actually the analog for stream.publish: http://developers.facebook.com/docs/reference/rest/stream.publish)
…Okay, in Facebook’s horrible documentation, I just found that streamPublish’s behavior also exists in FB.Connect.streamPublish: http://developers.facebook.com/docs/reference/oldjavascript/FB.Connect.streamPublish
However, unless I’m very confused (and note that I am), both of these can only take place on the JavaScript layer – I can’t trigger these directly from the AS3 API. (Which makes sense in a way, since they launch all these feed-forms, and I’ve never yet seen anything that I’ve called from AS3 that has properly launched a feed-form? But… I wish that did work.
Basically I want to, without requiring the user to grant publish_stream permission, and IF POSSIBLE without using any JavaScript, allow my app to initiate a feed publish, preferably by bringing up a standard feed-form pop-up.
Can I do this solely with the AS3 API? Or should I give up on that and go to using the FBJS bridge? I’m not familiar with how that works but I can switch to it if necessary… I would greatly value your advice Jozef!!!
Hi @IQpierce
thank you for appreciation my work
This article was written in the old REST API era. Now I recomment you to switch to OAuth/Graph API:
http://blog.yoz.sk/facebookoauthgraph/
The whole thing with facebook permissions is to inform user what is going on with his account. If you use javascript sdk to publish posts, the default facebook popup appears that user already know, and he has control over changing text etc. While using javascript sdk, or popup, or anythink that is created by facebook (plugins/widgets) and uses its common ui, you do not need to ask user for permissions… But if you use direct api call via client side or server side and permissions did not existed, any application could spam that users wall without noticing.
In order to open standard facebook publish stream lightbox (popup within the page) you have to use facebook javascript sdk:
http://developers.facebook.com/docs/reference/javascript/FB.ui (my best guess while I do not use it)
In order to open standart publish stream popup (new window) use sharer.php:
http://www.facebook.com/share/
http://developers.facebook.com/docs/share (read section Creating Your Own Share URL)
In order to publish stream from actionscript using new graph api you need publish_stream permission:
http://developers.facebook.com/docs/api (section Publishing to Facebook)
Man this is complex. Thanks for the reply Jozef…
Two concerns about using the Graph API:
1. I forgot to mention that my app is an IFrame Canvas app… and I recently read that Facebook recommends that Canvas app developers continue to use the old REST API: http://developers.facebook.com/docs/guides/canvas/ … Do you still recommend that I attempt to go through the new Graph API?
2. Again, I’m trying to do as much as possible entirely within AS3, and trying to use Adobe’s AS3 API for Facebook (http://code.google.com/p/facebook-actionscript-api/). This currently appears to only support the old REST API… and also appears to be poorly maintained (though there have recently been a couple of posts from an Adobe representative stating that it was going to be revised to support the Graph API and re-released in September). Do you have a reliable way to make calls against the Graph API directly from AS3? Is there some alternative to the AS3 API that’s just as easy-to-use and supports Graph?
Thanks again so much for all the great information you’re sharing here Jozef, I appreciate ANY help you can give on my questions!
Hi @IQpierce, you are welcome!
You can use iframe with the new graph api, just go through articles listed in here: http://blog.yoz.sk/facebookoauthgraph/ … REST API may become obsolete very soon (noone knows when exactly), you should really switch to the new one.
You are right, the original adobe facebook actionscript api is poorly maintained, latest update is more than 7 months old. The login and calls are far more easier with new oauth2 and graph than it used to be with adobe library, just try FacebookOAuthGraph lib to see the difference
i (re)start developing facebook apps with flash and your blogs helps very well. thanx for that!
but now I have a question: I have an image in my swf which I want to post via stream.Publish, but I don’t want to save it anywhere. I want to send it as bytearray/binary data to the wall of a friend. dou you know any way to do this or is this impossible?
I thought of two possible ways:
1. using your great Class with facebook.call(“method/stream.publish”, data, …); – but what should I put into media.imgsrc=…?
2. sending the bytearray to the DOM via javascript and then use the FBJS to send it to the users wall. I don’t know if that works (maybe this helps: http://www.adamia.com/blog/high-performance-javascript-port-of-actionscript-byteArray)
could you or anybody else help me out here?
thanx!!!!
maybe this one helps, too: http://blog.dannypatterson.com/?p=250
for diskussion, i opened a forum stream, too: http://forum.developers.facebook.net/viewtopic.php?pid=266991#p266991
Hi @HK, as far as I know facebook API stream attachments http://developers.facebook.com/docs/guides/attachments only lets you posting href (url) not the data directly. What is interesting facebook pulls the content from the url periodically (once a week or so). You can use http://developers.facebook.com/docs/reference/rest/photos.upload method (REST api) to upload raw bytes of photo into your album.
i strongly recommend to swith your app into new Graph API, while old REST API may become obsolete very soon.
@Jozef Chúťka: Hi! Thanx for answering! I use the FacebookOAuthGraph.as and don’t build on old REST.
So is there no hope for posting images on friends walls without pre-saving the image somewhere?
@HK I do not think so, you have to use href parameter – URL
@Jozef Chúťka: what about sending the raw data to JS? it would be great to be independant from serversiede scripts.
@HK based on the docs there is no way to do that, no client side “hack” will do the thing while facebook robot reads the content from the url! You have to save your content to server side before publishing it.