Facebook Developers
DocumentationSupportBlogAppsLog In
  • Getting Started
  • Core Concepts
  • Advanced Topics
    • Dialogs
    • FQL
    • Internationalization
    • Ads API
    • Credits
    • Chat API
    • Legacy REST API
    • Legacy FBML
    • Legacy FBJS
    • Legacy Javascript SDK
  • SDK Reference
  • Tools
  • Dialogs
    • Add Page Tab Dialog
    • Feed Dialog
    • Friends Dialog
    • OAuth Dialog
    • Pay Dialog
    • Requests Dialog
    • Send Dialog

Feed Dialog

Advanced Topics › Dialogs › Feed Dialog

Overview

The Feed Dialog prompts the user to publish an individual story to a profile's feed. This does not require any extended permissions.

Your application can also publish directly to a profile's feed without user interaction, use the corresponding Graph API call.

JavaScript Example

The following simple JavaScript example demonstrates using the FB.ui method in the JavaScript SDK to use the Feed Dialog:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:fb="https://www.facebook.com/2008/fbml">
  <head>
    <title>My Feed Dialog Page</title>
  </head>
  <body>
    <div id='fb-root'></div>
    <script src='http://connect.facebook.net/en_US/all.js'></script>
    <p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
    <p id='msg'></p>

    <script> 
      FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});

      function postToFeed() {

        // calling the API ...
        var obj = {
          method: 'feed',
          link: 'https://developers.facebook.com/docs/reference/dialogs/',
          picture: 'http://fbrell.com/f8.jpg',
          name: 'Facebook Dialogs',
          caption: 'Reference Documentation',
          description: 'Using Dialogs to interact with users.'
        };

        function callback(response) {
          document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
        }

        FB.ui(obj, callback);
      }
    
    </script>
  </body>
</html>

Note that the above example assumes that the user is already logged in and has authorized your application.

Direct URL Example

You can also bring up a Feed Dialog by explicitly directing the user to the /dialog/feed endpoint:

http://www.facebook.com/dialog/feed?
  app_id=123050457758183&
  link=http://developers.facebook.com/docs/reference/dialogs/&
  picture=http://fbrell.com/f8.jpg&
  name=Facebook%20Dialogs&
  caption=Reference%20Documentation&
  description=Using%20Dialogs%20to%20interact%20with%20users.&
  redirect_uri=http://www.example.com/response

Click here to try the url yourself. The user will see a dialog that looks like the following:

If the user clicks "Share", the browser will redirect to

http://www.example.com/response/?post_id=12345

The published story will look like this:

If the user clicks "Cancel", the browser will redirect to

http://www.example.com/response/

Graph API Equivalent

Using the Feed Dialog is equivalent to doing an HTTP POST to the /USER_ID/feed Graph API endpoint:

https://graph.facebook.com/brent/feed?
  link=http://developers.facebook.com/docs/reference/dialogs/&
  picture=http://fbrell.com/f8.jpg&
  name=Facebook%20Dialogs&
  caption=Reference%20Documentation&
  description=Using%20Dialogs%20to%20interact%20with%20users.&

Mobile Feed Dialog

On an iPhone, the following code makes an equivalent dialog:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  kAppId, @"app_id",
  @"http://developers.facebook.com/docs/reference/dialogs/", @"link",
  @"http://fbrell.com/f8.jpg", @"picture",
  @"Facebook Dialogs", @"name",
  @"Reference Documentation", @"caption",
  @"Using Dialogs to interact with users.", @"description",
  nil];

[_facebook dialog:@"feed" andParams:params andDelegate:self];

The above code generates the following dialog:

Properties

app_id

Your application's identifier. Required, but automatically specified by most SDKs.

redirect_uri

The URL to redirect to after the user clicks a button on the dialog. Required, but automatically specified by most SDKs.

display

The display mode in which to render the dialog. The default is page on the www subdomain. display=wap is currently not supported. This is automatically specified by most SDKs.

from

The ID or username of the user posting the message. If this is unspecified, it defaults to the current user. If specified, it must be the ID of the user or of a page that the user administers.

to

The ID or username of the profile that this story will be published to. If this is unspecified, it defaults to the the value of from.

link

The link attached to this post

picture

The URL of a picture attached to this post. The picture must be at least 50px by 50px and have a maximum aspect ratio of 3:1

source

The URL of a media file (either SWF or MP3) attached to this post. If both source and picture are specified, only source is used.

name

The name of the link attachment.

caption

The caption of the link (appears beneath the link name). If not specified, this field is automatically populated with the URL of the link.

description

The description of the link (appears beneath the link caption). If not specified, this field is automatically populated by information scraped from the link, typically the title of the page.

properties

A JSON object of key/value pairs which will appear in the stream attachment beneath the description, with each property on its own line. Keys must be strings, and values can be either strings or JSON objects with the keys text and href.

actions

A JSON array containing a single object describing the action link which will appear next to the "Comment" and "Like" link under posts. The contained object must have the keys name and link.

ref

A text reference for the category of feed post. This category is used in Facebook Insights to help you measure the performance of different types of post

Return Data

post_id

The ID of the posted story, if the user chose to publish.

Updated about 2 weeks ago
Facebook © 2012 · English (US)
AboutCareersPlatform PoliciesPrivacy Policy