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
  • Administrative Methods
    • admin.banUsers
    • admin.getAllocation
    • admin.getAppProperties
    • admin.getBannedUsers
    • admin.getRestrictionInfo
    • admin.setAppProperties
    • admin.setRestrictionInfo
    • admin.unbanUsers
    • application.getPublicInfo
    • batch.run
    • data.setCookie
    • fbml.setRefHandle
    • intl.getTranslations
    • intl.uploadNativeStrings
    • links.getStats
    • migrations.getStatuses
    • migrations.setStatus
    • pages.blockFan
  • Login/Auth Methods
    • auth.createToken
    • auth.expireSession
    • auth.getSession
    • auth.promoteSession
    • auth.revokeAuthorization
    • auth.revokeExtendedPermission
  • Data Retrieval Methods
    • comments.get
    • data.getCookies
    • fbml.refreshImgSrc
    • fbml.refreshRefUrl
    • fql.multiquery
    • fql.query
    • friends.areFriends
    • friends.get
    • friends.getAppUsers
    • friends.getLists
    • friends.getMutualFriends
    • groups.get
    • groups.getMembers
    • links.get
    • message.getThreadsInFolder
    • notes.get
    • notifications.get
    • notifications.getList
    • pages.getinfo
    • pages.isAdmin
    • pages.isAppAdded
    • pages.isFan
    • photos.get
    • photos.getAlbums
    • photos.getTags
    • privacy.get
    • profile.getFBML
    • profile.getInfo
    • profile.getInfoOptions
    • status.get
    • stream.get
    • stream.getComments
    • stream.getFilters
    • users.getInfo
    • users.getLoggedInUser
    • users.getStandardinfo
    • users.hasAppPermission
    • users.isAppUser
    • users.isVerified
    • video.getUploadLimits
  • Publishing Methods
    • comments.add
    • comments.remove
    • links.post
    • links.preview
    • liveMessage.send
    • notes.create
    • notes.delete
    • notes.edit
    • notifications.markRead
    • notifications.sendEmail
    • photos.addTag
    • photos.createAlbum
    • photos.upload
    • profile.setFBML
    • profile.setInfo
    • profile.setInfoOptions
    • status.set
    • stream.addComment
    • stream.addLike
    • stream.publish
    • stream.remove
    • stream.removeComment
    • stream.removeLike
    • users.setStatus
    • video.upload
  • Facebook Connect Methods
    • Mobile Methods
      • sms.canSend
      • sms.send
    • Dashboard API Methods
      • dashboard.decrementCount
      • dashboard.getCount
      • dashboard.incrementCount
      • dashboard.multiGetCount
      • dashboard.multiIncrementCount
      • dashboard.multiSetCount
      • dashboard.setCount
    • Events API Methods
      • events.cancel
      • events.create
      • events.edit
      • events.get
      • events.getMembers
      • events.invite
      • events.rsvp
    • Custom Tags API Methods
      • fbml.deleteCustomTags
      • fbml.getCustomTags
      • fbml.registerCustomTags
    • Ads Methods

      stream.publish

      Advanced Topics › Legacy REST API › stream.publish
      Please note: We are in the process of deprecating the REST API, so if you are building a new application you shouldn't use this function. Instead use the Graph API and POST a Post object to the `feed` connection of the User object

      This method publishes a post into the stream — on the Wall of the current or specified user, or on the Wall of a friend or a Facebook Page, group, or event connected to the current session or specified user (but not to an application profile page). 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 Stream Attachments.

      Note: The examples below are all server-side versions of the call in PHP. To see the JavaScript equivalents, check out FB.Connect.streamPublish.

      Updating a User's Status

      You can use this method to simply update a user's status. When you do so, the status message appears at the top of the user's profile and on the Friends > Status Updates page. The message also appears in the stream with your application icon.

      To use this method to set a user's status do the following:

      • Do not include an attachment or action link. If you do, the story will get published and will appear in the stream and on the user's Wall only. It won't appear at the top of the profile or in the Status Updates page.
      • Make sure the message is no longer than 420 characters. Otherwise, an error gets returned.

      Posting to Your Application's Profile Page

      In order to use stream.publish to post on the Wall of your application profile page (your application's About Page), all the following conditions must be true:

      • The posting user needs to grant the application the publish_stream extended permission.
      • The posting user must like the application's profile page.
      • A developer of the application must edit the application profile page's Wall Settings (Edit Application > Edit) and verify under Posting Ability that Fans can write or post content on the wall is checked.

      Parameters

      NameTypeDescription
      callbackstring

      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.

      messagestring

      The message the user enters for the post at the time of publication. If the message is a status update (that is, you're not including an attachment or an action link), it can contain up to 420 characters. Otherwise, if the post contains an attachment or action link, the message can contain up to 10,000 characters.

      attachmentobject

      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 this parameter. See Updating a User's Status above.

      action_linksarray

      A JSON-encoded array of action link objects, containing the link text and a hyperlink. If you want to use this call to update a user's status, don't pass this parameter. See Updating a User's Status above.

      target_idstring

      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.

      Note: If you specify a Page ID as the uid, you cannot specify a target_id. Pages cannot write on other users' Walls.

      Note: You cannot publish to an application profile page's Wall.

      uidstring

      The ID of the user or Page publishing the post. If this parameter is not specified, then it defaults to the session user. If you want to publish as page, you should use the 'enable_profile_selector' option with FB.login. This option enables the profile selector on the permission dialog.

      Note: If you specify a Page ID as the uid, you cannot specify a target_id. Pages cannot write on other users' Walls.

      privacyobject

      A JSON-encoded object that defines the privacy setting for a post, video, or album. It contains the following fields.

      • value (string): The privacy value for the object, specify one of EVERYONE, CUSTOM, ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, SELF.
      • friends (string): For CUSTOM settings, this indicates which users can see the object. Can be one of EVERYONE, NETWORKS_FRIENDS (when the object can be seen by networks and friends), FRIENDS_OF_FRIENDS, ALL_FRIENDS, SOME_FRIENDS, SELF, or NO_FRIENDS (when the object can be seen by a network only).
      • networks (string): For CUSTOM settings, specify a comma-separated list of network IDs that can see the object, or 1 for all of a user's networks.
      • allow (string): When friends is set to SOME_FRIENDS, specify a comma-separated list of user IDs and friend list IDs that ''can'' see the post.
      • deny (string): When friends is set to SOME_FRIENDS, specify a comma-separated list of user IDs and friend list IDs that ''cannot'' see the post.

      Only the user can specify the privacy settings for the post. You can create an interface that lets the user specify the privacy setting. For CUSTOM settings, use friends.get and friends.getLists to get the user's friends and friend lists to populate the interface, then pass along the selections to the privacy object.

      Note: This privacy setting only applies to posts to the current or specified user's own Wall; Facebook ignores this setting for targeted Wall posts (when the user is writing on the Wall of a friend, Page, event, group connected to the user). Consistent with behavior on Facebook, all targeted posts are viewable by anyone who can see the target's Wall.

      Privacy Policy: Any non-default privacy setting must be intentionally chosen by the user. You may not set a custom privacy setting unless the user has proactively specified that they want this non-default setting.

      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.

      Updated about a week ago
      Facebook © 2012 · English (US)
      AboutCareersPlatform PoliciesPrivacy Policy