FeedStory form

From Facebook Developer Wiki

Jump to: navigation, search

Contents

Description

Facebook will deprecate this Feed form method December 20, 2009.

Please start using FB.Connect.streamPublish and Facebook.streamPublish instead.


The Feed story form is special FBML element that allows your application to publish approved Feed stories directly to a user's Wall. (You can publish directly to a user's friend's Wall with MultiFeedStory_form).

To use the Feed form, create a standard HTML <form> with this special fbtype="feedStory" attribute and a standard form input submit button. We intercept the submit click.

You need to provide an action callback. On form submission, we ping your callback and wait for a response from you containing the Feed story and the follow-up URL to where the user gets redirected after publishing or canceling the form. For example, the story is specified by $feed and the follow-up URL is specified by next in the JSON example below. Or you could pass next_fbjs instead and execute JavaScript after publishing or canceling.

Read more about Feed forms.

Attributes

RequiredNameTypeDescription
required fbtype string Must be "feedStory."
action string The callback to a feedStory feed handler.

Response Content

Facebook expects the following arguments from the response endpoint.

RequiredNameTypeDescription
required feed array The Feed story bundle.
next string The page to load after the Feed dialog appears.
optional next_fbjs string JavaScript to run after the form is done. (You can use this parameter instead of the next parameter.)

Examples

Mood Picker

<form fbtype="feedStory" action="http://my.app/feed_handler.php"> <select size=3 name="mood"> <option value="happy" selected="true"> happy </option> <option value="sad"> sad </option> <option value="angry"> angry </option> </select> <input type="submit" label="Mood Pick" /> </form>


Mood Pick Handler (JSON PHP)

<?php $feed = array('title_template' => "{actor} is feeling {mood} today", 'template_data' => array("mood"=>$_POST['mood']), 'template_id' => XXXXXXXXX); $publish = array('method'=> 'feedStory', 'content' => array( 'feed' => $feed, 'next' => 'http://apps.facebook.com/moodpicker/next_page.php')); echo json_encode($publish);


Mood Pick Handler (Ruby on Rails)

url = "http://apps.facebook.com/yourapp/nextpage" data = { :title_template => '{actor} is feeling {mood} today', :title_data => { :mood => params[:mood] }} feedStory = { :method => 'feedStory', :content => { :feed => data, :next => url }} render :text => feedStory.to_json

Notes

  1. The action of the form must be an absolute URL or the form will not render.
  2. If you are using Ruby On Rails version 1.2.x, use the JSON gem instead of the to_json method because the default Rails 1.2.x to_json method will render incorrectly formatted JSON output.
  3. If you see a Facebook error on your page that says "null" was returned in the JSON output from your callback page, it is most likely that the output rendered is not formatted correctly.
reference