Sharing to Messenger for iOS and Android
Updated: Mar 1, 2023
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:
- Link Share (The same as the existing link share but with a
pageIDfor attribution) - Photo (Unattributed)
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 |
|
Linking App and Page IDs
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:
- Go to the Settings for the Page.
- Click on the Messenger Platform section.
- Go to the Link an App section in General Settings”.
- Enter the app ID and click the Link button.
- If this app was NOT in the Subscribed Apps table already, it will show up in the table with the “share attribution” role associated with it. If the app was already in the table, the new “share attribution” role will be added for that app.
Page administrators can also remove an app’s permission to use share attribution.
To remove the “share attribution” role for a given app:
- In the Subscribed Apps table, click on the dropdown in the “role” column for the app.
- Click on the “share attribution” to deselect the role.
- If “share attribution” was the only role for the app, the row for the app is removed from the table. Otherwise, the row remains but the “share attribution” row is deselected.
Registering Domains
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:
- View the Page.
- Navigate to Settings > Advanced Messaging.
- Add the domain to the Whitelisted Domains field.
For more information, see Messenger Extensions SDK - Required Domain Whitelisting.
iOS
Prerequisites
Before you add sharing to Messenger to your app, complete the following steps:
- Add the Facebook SDK for iOS to your mobile development environment
- Configure and link your Facebook app ID to your Page ID with the Messenger Platform tool.
- Add your app ID, display name, and human-readable reason for photo access to your app’s
.plistfile. - Link the
FBSDKShareKit.frameworkto 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.Limitations
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()
Android
Prerequisites
Follow the instructions in Sharing on Android, summarized below:
- To use the Facebook Sharing SDK in your project, make it a dependency in Maven, or download it.
- Get a Facebook App ID properly configured and linked to your Android app.
- Configure and link your Facebook app ID to your Page ID with the Messenger Platform tool.
- Generate an Android Key Hash and add it to your developer profile.
- Add a Facebook Activity and include it in your AndroidManifest.xml
Also make sure your app calls
MessageDialog.canshow({template}) to determine whether people have a compatible version of Messenger installed on their devices.