Facebook.streamPublish

From Facebook Developer Wiki

Jump to: navigation, search

Contents

Description

This FBJS method publishes a post into the stream on the Wall of a user or a Facebook Page, group, or event connected to the user. By default, this call publishes to the current session user's Wall, but if you specify a user ID, Facebook Page ID, group ID, or event ID as the target_id, then the post appears on the Wall of the target, and not the user posting the item.

The post also appears in the streams (News Feeds) of any user connected to both the actor and the target of the post.

This method works in two ways. You can use it to publish:

  • As a Feed form. Keep the auto_publish parameter set to the default, false, so the Feed form appears. You do not need the publish_stream permission to publish in this manner.
  • Directly to a user's or Page's stream, without prompting the user. Before your application can publish directly to the stream, the user or Page must grant your application the publish_stream extended permission. If the user previously granted your application the permission to publish short stories into the News Feed automatically, then you don't need to prompt for this permission in order to call this method. Make sure you set the auto_publish parameter to true.

This method takes similar parameters to stream.publish. The main difference between calling this function and calling stream.publish is that if the user hasn't granted your application the publish_stream extended permission, or if the auto_publish parameter is set to false (the default), a Feed form appears, asking the user to confirm the post before publishing.

You can give your users the opportunity to add their own message to the post.

To provide rich content like MP3 audio, Flash, or an image, you can supply a predefined object called attachment. Facebook formats the attachment into the post. The attachment is described in Attachment (Streams).

If the user isn't logged in to Facebook when you make this call, a login dialog appears, followed by a dialog with the post data.

Parameters

RequiredNameTypeDescription
optional user_message string The message the user enters for the post at the time of publication.
attachment object A dictionary object containing the text of the post, relevant links, a media type (image, mp3, flash), as well as any other key/value pairs you may want to add. See Attachment (Streams) for more details.
Note: If you want to use this call to update a user's status, don't pass an attachment; the content of the user_message parameter will become the user's new status and will appear at the top of the user's profile.
action_links object A dictionary containing an action link object, containing the link text and a hyperlink.
target_id string The ID of the user, Page, group, or event where you are publishing the content. If you specify a target_id, the post appears on the Wall of the target profile, Page, group, or event, not on the Wall of the user who published the post. This mimics the action of posting on a friend's Wall on Facebook itself.
user_message_prompt string Text you provide the user as a prompt to specify a user_message. This appears above the box where the user enters a custom message. For example, "What's on your mind?"
callback string Callback to execute after the function completes. It takes three parameters:
  • post_id, which returns the ID of the published post. This can be null if the user cancels publishing.
  • exception, which returns the error description if an error occurred.
  • data, which currently has one defined key: user_message. user_message contains the text the user entered in the Feed form for the post.
auto_publish bool Indicates whether to automatically publish to the user's stream without displaying a Feed form to the user. If the user has granted your application the publish_stream extended permission and this parameter is set to true, the post is published automatically. (Default value is false.)
actor_id string Allows the logged in user to publish on a Facebook Page's behalf if the user is an admin of the Page. If specified, actor_id indicates the ID of the Page that will publish the post. If the user publishes the post, the post will appear on the Page's Wall as if the Page has posted it. (Default value is null.)

Example Requests

Prompt a user to update his or her status only.

Facebook.streamPublish();


Prompt a user to update his or her stream with an image attachment.

var attachment = {'media':[{'type':'image','src':'http://bit.ly/AJTnf','href':'http://bit.ly/hifZk'}]}; Facebook.streamPublish('', attachment);


Prompt a user to write on his or her friend's Wall.

Facebook.streamPublish('', attachment, null, 4)


Prompt a user to post an image, then check results in a callback.

function callback (post_id, exception) { if(post_id) { post_to_my_server(post_id); } } Facebook.streamPublish('', attachment, null, null, 'What do you think?', callback);

Notes

See Also

reference