Facebook PublishPost with image (update)

facebookPublishPost

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

54 comments so far

  1. 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 😀

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

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

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