Stream.publish
From Facebook Developer Wiki
Contents |
Description
This 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.
Before your application can publish to the stream using this method, 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.
Note: To give users control over what gets published to their streams, you should use Feed forms (rendered with Facebook.streamPublish or FB.Connect.streamPublish) instead of stream.publish. This method is intended to be used in cases where Feed forms are not available or do not make sense in the natural workflow. For more information, read about the publish_stream permission.
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 JSON-encoded object called attachment. Facebook formats the attachment into the post. The attachment is described in Attachment (Streams).
Note: The examples below are all server-side versions of the call in PHP. To see the JavaScript equivalents, check out http://developers.facebook.com/docs/?u=facebook.jsdocs.FB.Connect.streamPublish.
Parameters
| Required | Name | Type | Description | |
| optional | session_key | string | The session key of the logged in user. The session key is automatically included by our PHP client. This is only required if you don't specify a uid, or if a desktop application calls stream.publish. | |
|---|---|---|---|---|
| format | string | The desired response format, which can be either XML or JSON. (Default value is XML.) | ||
| callback | string | Name of a function to call. This is primarily to enable cross-domain JavaScript requests using the <script> tag, also known as JSONP, and works with both the XML and JSON formats. The function will be called with the response passed as the parameter. | ||
| message | string | The message the user enters for the post at the time of publication. | ||
| attachment | object | A JSON-encoded 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 message parameter will become the user's new status and will appear at the top of the user's profile. | ||
| action_links | array | A JSON-encoded array of action link objects, 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. | ||
| uid | string | The user ID or Page ID of the user or Page publishing the post. If this parameter is not specified, then it defaults to the session user. If you specified a session_key, and that session user is a Page admin, then you can specify a Page ID here to publish to one Page for which the session user is an admin. |
Setting a User's Status.
Publishing a Post Containing an Image, Action Link, and Custom Metadata
Publishing a Post Containing Flash, Action Link, and a Target
Publishing a Post With Image and Action Link in C#
Publishing a Post With Image and Action Link in C# using facebook developer toolkit v2
Response
This call returns a post_id string containing the ID of the stream item upon success. If the call fails, it returns an error code instead.
Error Codes
| Code | Description | |
| 1 | An unknown error occurred. | |
|---|---|---|
| 100 | Invalid parameter. | |
| 102 | Session key invalid or no longer valid (if it's a desktop application and the session is missing). | |
| 200 | Permissions error. The application does not have permission to perform this action. | |
| 210 | User not visible. The user doesn't have permission to act on that object. | |
| 340 | Feed action request limit reached. |
Notes
You can call this method using a session secret, and not the application secret (for example, for a Facebook Connect site or desktop application).
