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
  • FB.CanvasClient
    • FB.CanvasClient.add_windowSizeChanged
    • FB.CanvasClient.getCanvasInfo
    • FB.CanvasClient.get_timerInterval
    • FB.CanvasClient.remove_windowSizeChanged
    • FB.CanvasClient.setCanvasHeight
    • FB.CanvasClient.set_timerInterval
    • FB.CanvasClient.startTimerToSizeToContent
    • FB.CanvasClient.stopTimerToSizeToContent
  • FB.Connect
    • FB.Connect.addSignedPublicSessionDataToUrl
    • FB.Connect.createApplication
    • FB.Connect.forceSessionRefresh
    • FB.Connect.getSignedPublicSessionData
    • FB.Connect.getUIServerDialogProperty
    • FB.Connect.get_loggedInUser
    • FB.Connect.get_status
    • FB.Connect.ifUserConnected
    • FB.Connect.inviteConnectUsers
    • FB.Connect.isUIServerEnabled
    • FB.Connect.logout
    • FB.Connect.logoutAndRedirect
    • FB.Connect.pollLoginStatus
    • FB.Connect.requireSession
    • FB.Connect.showAddFriendDialog
    • FB.Connect.showAddSectionButton
    • FB.Connect.showBookmarkDialog
    • FB.Connect.showFeedDialog
    • FB.Connect.showPermissionDialog
    • FB.Connect.showProfileTabDialog
    • FB.Connect.showUIServerDialog
    • FB.Connect.streamPublish
  • FB.ApiClient
    • FB.ApiClient.auth_getAppPublicKey
    • FB.ApiClient.auth_getSignedPublicSessionData
    • FB.ApiClient.callMethod
    • FB.ApiClient.connect_getUnconnectedFriendsCount
    • FB.ApiClient.events_get
    • FB.ApiClient.events_getMembers
    • FB.ApiClient.fbml_refreshImgSrc
    • FB.ApiClient.fbml_refreshRefUrl
    • FB.ApiClient.feed_getAppFriendStories
    • FB.ApiClient.feed_publishUserAction
    • FB.ApiClient.fql_query
    • FB.ApiClient.friends_get
    • FB.ApiClient.get_apiKey
    • FB.ApiClient.get_session
    • FB.ApiClient.get_sessionWaitable
    • FB.ApiClient.pages_getInfo
    • FB.ApiClient.pages_isAdmin
    • FB.ApiClient.pages_isAppAdded
    • FB.ApiClient.pages_isFan
    • FB.ApiClient.photos_addTag
    • FB.ApiClient.photos_createAlbum
    • FB.ApiClient.photos_get
    • FB.ApiClient.photos_getAlbums
    • FB.ApiClient.photos_getTags
    • FB.ApiClient.preloadFQL_get
    • FB.ApiClient.requireLogin
    • FB.ApiClient.revokeAuthorization
    • FB.ApiClient.sessionIsExpired
    • FB.ApiClient.set_session
    • FB.ApiClient.stream_get
    • FB.ApiClient.stream_getComments
    • FB.ApiClient.stream_getFilters
    • FB.ApiClient.users_getInfo
    • FB.ApiClient.users_hasAppPermission
    • FB.ApiClient.users_isAppAdded
    • FB.ApiClient.users_isAppUser
    • FB.ApiClient.users_setStatus
  • FB.XFBML.Host
    • FB.XFBML.Host.get_areElementsReady
    • FB.XFBML.Host.parseDomElement
    • FB.XFBML.Host.parseDomTree
    • FB.XFBML.Host.refresh
  • FB.XFBML.Conditions
    • FB.XFBML.Conditions.ifCanSee
  • FB.Monitor
    • FB.Monitor.bind
    • FB.Monitor.copy
    • FB.Monitor.disableLogging
    • FB.Monitor.externalCallback
    • FB.Monitor.forEach
    • FB.Monitor.logFunction
    • FB.Monitor.logXFBML
    • FB.Monitor.loggingEnabled
    • FB.Monitor.provide
    • FB.Monitor.redo
    • FB.Monitor.resolve
    • FB.Monitor.scheduleSend
    • FB.Monitor.send
    • FB.Monitor.subclass
    • FB.Monitor.wrapObject
  • FB.Facebook
    • FB.Facebook.add_initCalled
    • FB.Facebook.get_baseDomain
    • FB.Facebook.get_initialized
    • FB.Facebook.get_isInCanvas
    • FB.Facebook.get_isInConnect
    • FB.Facebook.get_sessionState
    • FB.Facebook.get_sessionWaitable
    • FB.Facebook.init
    • FB.Facebook.remove_initCalled
    • FB.Facebook.set_baseDomain
  • FB.Waitable
    • FB.Waitable.add_changed
    • FB.Waitable.onChange
    • FB.Waitable.remove_changed
    • FB.Waitable.resetChange
    • FB.Waitable.waitForCondition
    • FB.Waitable.waitForValue
    • FB.Waitable.waitUntilReady
  • FB.BatchSequencer
    • FB.BatchSequencer.execute
  • FB.PendingResult
    • FB.PendingResult.setPendingResult

FB.Connect.streamPublish

Advanced Topics › Legacy Javascript SDK › FB.Connect.streamPublish

This method publishes a post to the user's stream using stream.publish. If you specify a 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 user and the target of the post.

This method works in one of two ways:

  • To display a Feed form to the user. The user does not need to have any permissions with your site to publish in this manner. If the user isn't logged into Facebook then a login popup will appear, followed by a dialog with the stream story. Users can add their own message to the post.

  • To publish directly to the user's stream, without any additional prompting. Before your application can publish directly, the user must grant the extended permission. Set the auto_publish parameter to true.

This is the JavaScript client version of the api:stream.publish API call. You use the JavaScript call when the user may have not authorized your site, or has not granted the [publish_stream] wiki:Extended_permissions/Stream_permissions permission.

You can supply a predefined object called attachment. Facebook displays a preview of the attachment to the user as it will look when it appears on the user's Wall.

Examples ————

  • Prompt a user to update his or her status:

    FB.Connect.streamPublish();
    
  • Prompt a user to update his or her stream with an image attachment:

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

    )}; FB.Connect.streamPublish('', attachment);

  • Prompt a user to post to a friend's Wall:

    FB.Connect.streamPublish('', attachment, null, 4);
    
  • Prompt a user to post a image, then check the results:

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

Parameters

NameTypeDescription
user_messageString

The main user-entered message for the post. This field should typically be blank- only fill this field with content the user has actually entered themselves.

attachmentObject

A dictionary object containing the text of the post, relevant links, and optionally a media type. You can also include other key/value pairs which will be stored as metadata. See Stream Attachments for details.

action_linksObject

A dictionary of Action links objects, containing the link text and a hyperlink.

target_idString

The ID of the user or the Page where you are publishing the content. If you specify a target_id, the post appears on the wall of the target user, not the user that published the post. This mimics the action of posting on a friend's Wall.

user_message_promptString

The sentence that appears before the user message field (e.g. "What's on your mind?")

callbackFunction

A function that takes two parameters: post_id and exception. post_id returns the id of the published post (which can be null if the user cancels). exception returns error description if an error occurred.

auto_publishBoolean

If the user has granted the publish_stream extended permission AND this parameter is true, then the post will be published without user approval. If the user has not set the extended permission, then the method will fail. (Default value is false)

actor_idString

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. The post will appear on the Page's Wall as if the Page had posted it. (Default value is null)

Updated over a year ago
Facebook © 2012 · English (US)
AboutCareersPlatform PoliciesPrivacy Policy