The Share dialog gives people the ability to publish an individual story to their timeline, a friend's timeline, a group, or in a private message on Messenger. This does not require Facebook Login or any extended permissions, so it is the easiest way to enable sharing on the web.
If people are in a browser that is not logged in with a cookie, the drop-down list for choosing the audience for your share doesn't appear. This is also true if the app uses the feed dialog instead of the share dialog or if the app uses iframe web view.
To implement the Share Dialog in native mobile apps read our guides for iOS and Android.
The Share dialog is available in the Facebook SDK for JavaScript. You can use the following code snippet to trigger the Share dialog. You can also use a redirect to a URL. For details, see Advanced Topics.
Trigger a Share Dialog using the FB.ui function with the share
method parameter to share a link.
To share a link:
FB.ui({ method: 'share', href: 'https://developers.facebook.com/docs/', }, function(response){});
Include open graph meta tags on the page at this URL to customize the story that is shared back to Facebook.
Note that response.error_message
will appear only if someone using your app has authenciated your app with Facebook Login.
The JS SDK will provide these parameters automatically.
Parameter | Description |
---|---|
| Your app's unique identifier. Required. |
| The URL to redirect to after a person clicks a button on the dialog. Required when using URL redirection. |
| Determines how the dialog is rendered.
|
share
ParametersParameter | Description | Default |
---|---|---|
| The link attached to this post. Required when using method | Current URL |
| A hashtag specified by the developer to be added to the shared content. People will still have the opportunity to remove this hashtag in the dialog. The hashtag should include the hash symbol, e.g. |
|
| A quote to be shared along with the link, either highlighted by the user or predefined by the developer, as in a pull quote on an article. |
|
mobile_iframe Deprecated | true the share button will open the share dialog in an iframe on top of your website (For more information see Mobile Web Share Dialog. This option is only available for mobile, not desktop. | false |
Parameter | Description |
---|---|
| Only available if the user is logged into your app using Facebook Login. |
You can also take advantage of the following advanced features.
To share a link:
https://www.facebook.com/dialog/share? app_id=145634995501895 &display=popup &href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2F &redirect_uri=https%3A%2F%2Fdevelopers.facebook.com%2Ftools%2Fexplorer
Note: When testing this code, remove the line breaks. Otherwise you will run into an error.