When you develop with the Facebook SDK for iOS or Android version 4.29.0 or later, you can enable people to share both links and media from your apps to Messenger. When a user shares to Messenger you can trigger your chat extensions through the attribution link. Your chat extensions appear in the More section of the sharing interface.
For more information, see the following sections:
For implementing sharing to Messenger for the web, see Sharing to Messenger for the Web.
The Facebook SDK provides the following share types:
pageID
for attribution)The following table lists all the share types supported in sharing to Messenger, along with whether a Page or App ID is required.
Share Type | Page ID Required? | Applications |
---|---|---|
Link Share | Optional |
|
Photo | Not supported |
|
Developers can specify a Page ID in the share flow, and when people share content from an app to messenger by way of the Sharing SDK, the content is attributed to the Page. Page administrators, in turn, can prevent false attributions by controlling which apps can use a share attribution for their Pages. To grant an app share attribution, the administrator links the app's ID with the Page ID.
To link an app ID and Page ID:
Page administrators can also remove an app's permission to use share attribution.
To remove the “share attribution” role for a given app:
If you use a URL button in the Share SDK and want to enable Messenger Extension for your URL when opened in Messenger, you have to register the URL domain for the share to work correctly.
To register a domain:
For more information, see Messenger Extensions SDK - Required Domain Whitelisting.
Before you add sharing to Messenger to your app, complete the following steps:
.plist
file.FBSDKShareKit.framework
to your project.For more information, see Getting Started with the Facebook SDK for iOS
Also make sure your app calls canShow
or validate
on the MessageDialog
instance to determine whether people have a compatible version of Messenger installed on their devices.
The quote property is not supported.
guard let url = URL(string: "https://newsroom.fb.com/") else { preconditionFailure("URL is invalid") } let content = ShareLinkContent() content.contentURL = url let dialog = MessageDialog(content: content, delegate: self) do { try dialog.validate() } catch { print(error) } dialog.show()
// Assumes your assets contain an image named "puppy" guard let image = UIImage(named: "puppy") else { return } let photo = SharePhoto(image: image, userGenerated: true) let content = SharePhotoContent() content.photos = [photo] let dialog = MessageDialog(content: content, delegate: self) // Recommended to validate before trying to display the dialog do { try dialog.validate() } catch { print(error) } dialog.show()
// Assuming you have a URL for a PHAsset let video = ShareVideo(videoURL: assetURL) let content = ShareVideoContent() content.video = video let dialog = MessageDialog(content: content, delegate: self) // Recommended to validate before trying to display the dialog do { try dialog.validate() } catch { print(error) } dialog.show()
Follow the instructions in Sharing on Android, summarized below:
Also make sure your app calls MessageDialog.canshow({template})
to determine whether people have a compatible version of Messenger installed on their devices.