O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Feed Forms: Publishing Feed Stories from FBML

Problem

I’d like to give my users the ability to publish Mini-Feed stories about themselves or about their friends by completing a form in my app.

Solution

To create a form through which users can publish stories to their own Mini-Feed, include an HTML form with the special fbtype attribute to signify that Facebook should use it as a Feed Form:

<form fbtype="feedStory" action="http://someserver.com/feed_handler.php">
    <input type="text" name="status" />
    <input type="hidden" name="template_id" value="12345678901" />
    <input type="submit" label="Publish" />
</form>

You can include any fields, content, and controls you’d like in the form. On submit, Facebook will send the form to the URL specified in the action, and will then take your JSON-formatted response back and use it to render a preview of a story. For the example just shown, your server-side feed_handler.php page could be as simple as:

{"method":"feedStory", "content":{
    "next":"http://apps.facebook.com/myapp/somepage",
    "feed":{
        "template_id":"<?php echo $_POST['template_id']?>",
        "template_data":{"status":"<?php echo $_POST['status']?>"}}}}

Depending on what template 12345678901 contained, the story preview for this example might look like Figure 6-60.

Feed Form preview

Figure 6-60. Feed Form preview

Discussion

We aren’t, of course, setting the status in the previous example, though we could quite easily, as the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required