Facebook wall post style


facebookStream publish is one of the vital issue in facebook application or facebook connect base application. If you want to publish stream from your facebook application or facebook page application then you have to call

Facebook.streamPublish();

method with some parameters. If you want to publish from facebook connect base application then you have to call

FB.Connect.streamPublish()

with some parameters. One of the important parameter is the second parameter named attachment. Using this parameter you can add video, flash, text etc. This parameter actually is an object that contains text information, caption and other media like flash, music. But in text information that is called description you couldn’t use html. But suppose you have a quiz application and when user will publish stream you want some questions and answers will publish nicely. like this

Then you have to use another parameter that is called properties. Properties is also a part of the attachment parameter. So now look at the code how could you do this

<script type="text/javascript">
function streamPublish(){
    var baseUrl    = "http://yoursite.com/yourpage.html";
    var imgUrl      = baseUrl + "/logo.jpg";  //set image if you have
    var hrefUrl     = baseUrl;

    var prop  = {
        "1. What is your name "         :  "mahmud",
        "2. What is your occupation " : "engineer",
        "3. Where do you live "          : "dhaka"
    };

    var attachment  = {'caption': 'Title: About Me', 'properties': prop, 'media':[{'type':'image','src':imgUrl, 'href': hrefUrl}]};

    var actionLinks = [{ "text": "Give your answers", "href": baseUrl}];

    FB.Connect.streamPublish('', attachment, actionLinks, null, "Post your answer", fbCall);
}
</script>
<a href="#" onclick="streamPublish()">Publish Stream</a>

So use this code and modify for your fbconnect base application. If you want to use this code for facebook application or facebook page application just replace FB.Connect by Facebook.

References:

  1. http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
  2. http://wiki.developers.facebook.com/index.php/Facebook.streamPublish
mahmud ahsan

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

5 Comments

  • Tesfalem
    December 22, 2010 at 12:36 am

    Thank you so much for you help, your tutorial helped me a lot, and am able to create my own application now.

    i was trying this code to make , when users load my application some thing like “user_name is using this application” massage on their wall post automatically with out the pop up box. pleas help me Mahmud with the code , and do i have to put the code inside the “templet.php or index.php which loads the HTMl file?

    Thank you so much ones again.

  • Tesfalem
    December 24, 2010 at 12:17 am

    thanks you so much for your fast replay dear.

    i actually don’t have PHP skill but i did a good application using your tutorial (thanks to you).

    i try this code from one of your tutorials which publish on their wall automatically when they load the page. but it only publish , the message . i dont know how to make the $attachment code inorder to publish,
    -name of the app
    -message
    -link and image on of the app to their wall using this code.
    here is the code i got form one of your tutorial

    ‘Amharic’, ‘href’=>’http://apps.facebook.com/type-amharic’)));

    $param = array(
    ‘method’ => ‘stream.publish’,
    ‘callback’ => ”,
    ‘message’ => “Is Using Geez fonts to Type Amharic start using Geez fonts ==> http://apps.facebook.com/type-amharic/ “,
    ‘attachment’ => ”,
    ‘action_links’ => $actions,
    ‘target_id’ => ”,
    ‘uid’ => ”,
    ‘privacy’ => ”
    );
    $result = $facebook->api($param);
    }
    catch(Exception $o) {
    }

    ?>

    how can i add the link, image, name of app with the message? pleas help me with some codes,

    thank you so much and i really love you tutorial Mahmud

  • Tesfalem
    December 24, 2010 at 12:19 am

    Thx Mahmud.

    i actually don’t have PHP skill but i did a good application using your tutorial (thanks to you).

    i try this code from one of your tutorials which publish on their wall automatically when they load the page. but it only publish , the message . i dont know how to make the $attachment code inorder to publish,
    -name of the app
    -message
    -link and image on of the app to their wall using this code.
    here is the code i got form one of your tutorial

    ‘Amharic’, ‘href’=>’http://apps.facebook.com/type-amharic’)));

    $param = array(
    ‘method’ => ‘stream.publish’,
    ‘callback’ => ”,
    ‘message’ => “Is Using Geez fonts to Type Amharic start using Geez fonts ==> http://apps.facebook.com/type-amharic/ “,
    ‘attachment’ => ”,
    ‘action_links’ => $actions,
    ‘target_id’ => ”,
    ‘uid’ => ”,
    ‘privacy’ => ”
    );
    $result = $facebook->api($param);
    }
    catch(Exception $o) {
    }

    ?>

    how can i add the link, image, name of app with the message? pleas help me with some codes,

    thank you so much and i really love you tutorial Mahmud

  • yasir
    April 21, 2011 at 1:38 am

    hi i really like ur tutorials,,,,, they r really helpful…. currently m developing a fb app which is mainly concerned with the security of people who r moving from 1 place to another….. so i ve created a form which is storing taxi no. and location in mysql database ….. now i m stuck at place where i need to take out those data value and print it on the walls of 5 friends choosed acc to me….. could u plzz help me in this code/.???

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage