Sharing to Messenger for iOS and Android

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.

Share Types

The Facebook SDK provides the following share types:

  • Link Share (The same as the existing link share but with a pageID for 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

  • Link without attribution
  • Link with attribution

Photo

Not supported

  • Photos
  • Photo from library

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:

  1. Go to the Settings for the Page.
  2. Click on the Messenger Platform section.
  3. Go to the Link an App section in General Settings”.
  4. Enter the app ID and click the Link button.
  5. 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:

  1. In the Subscribed Apps table, click on the dropdown in the “role” column for the app.
  2. Click on the “share attribution” to deselect the role.
  3. 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:

  1. View the Page.
  2. Navigate to Settings > Advanced Messaging.
  3. 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 .plist file.
  • Link the 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.

Limitations

The quote property is not supported.

Link Share Example

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()

Photo Share Example

// 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()

Video Share Example

// 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:

Also make sure your app calls MessageDialog.canshow({template}) to determine whether people have a compatible version of Messenger installed on their devices.