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.
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 ...
Get Facebook Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.