Feed forms
From Facebook Developers Wiki
Feed forms are special FBML components that allow applications to publish Feed stories on behalf of their users. There are two types of Feed forms:
- feedStory, which you use to publish stories to the current user's Mini-Feed.
- multiFeedStory, which you use to publish stories to friends' Mini-Feeds.
You create a Feed form using a standard HTML <form> tag marked with a special fbtype attribute. The rest of the form works exactly like a normal HTML form. Feel free to put whatever elements you need to collect information, to create the object behind the story.
| <form fbtype="feedStory" action="http://my.canvas.com/feed_handler.php"> <input type="text" name="status" /> <input type="submit" value="Publish" /> </form> |
When the user submits the form, Facebook does some special handling of the form behind the scenes (similar to how we handle fb:request-form). We intercept the submission and pass it along with the form data to your action attribute. Instead of sending back FBML, your application should send back a JSON response with the Feed story. A basic response is a simple title and body.
| {"method" : "feedStory", "content": { "next": "http://my.canvas.com/next_page.php", "feed": {"title_template": "{actor} published status", "body_template" : "New status is \"{status}\"", "body_data" : {"status": "Here is the status"} } |
We provide some helper functions for this in the PHP client.
| $feed = $fb->create_templatizedFeedStory('{actor} published status', array(), 'New status is "{status}", array('status'=>'Here is the status'); $data = $fb->encode_multiFeedStory($feed, 'http://my.canvas.com/next_page.php'); echo $data; |
The $feed structure follows the same schema as the Feed.publishTemplatizedAction API call.
Once the data is returned we display a preview to the user and give him the option of publishing the story.
The application also has the option of blocking the Feed story because of validation or other data issues. If we receive an error code, then we let you display an error message.
| {"errorCode": 1, "errorTitle" => "Status Error", "errorMessage" => "That status was not very exciting" } |
At the moment, the only error code is for validation errors. Here is an example in PHP.
| echo encode_validationError('Status Error', 'That status was not very exciting'); |
