Last June, we announced plans to no longer support the Share to Messenger SDK. We are excited to share we will continue to support a modified version of the Share to Messenger SDK, which will allow people to share links and photos from your app to Messenger. The support for link and image/video sharing on the iOS Messenger app will be rolled out gradually over the next few weeks. We will no longer support sharing generic and media templates. If you still have the SDK in your app, no action is required.
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. These shares can be used to trigger your chat extensions via the attribution link. They will also put your chat extension in the more drawer for the sharer.
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 four attributed share types and one unattributed 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, and ways of using the template.
Share Type | Page ID Required? | Applications |
---|---|---|
Optional |
| |
Required |
| |
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 whitelist the URL domain for the share to work correctly.
To whitelist a domain:
For more information on whitelisting, 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
on the FBSDKMessageDialog
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()
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init]; content.contentURL = [NSURL URLWithString:@"https://newsroom.fb.com/"]; FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init]; messageDialog.shareContent = content; if ([messageDialog canShow]) { [messageDialog 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()
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init]; NSArray<FBSDKSharePhoto *> *photos = @[ [FBSDKSharePhoto photoWithImage:[UIImage imageNamed:@"thumbs_up.jpg"] userGenerated:YES], ]; content.photos = photos; FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init]; messageDialog.shareContent = content; if ([messageDialog canShow]) { [messageDialog 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()
// Assuming you have a URL for a PHAsset FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init]; content.video = [FBSDKShareVideo videoWithVideoURL:assetURL]; FBSDKMessageDialog *messageDialog = [[FBSDKMessageDialog alloc] init]; messageDialog.shareContent = content; if ([messageDialog canShow]) { [messageDialog 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.
ShareMessengerURLActionButton actionButton = new ShareMessengerURLActionButton.Builder() .setTitle("Visit Facebook") .setUrl(Uri.parse("https://www.facebook.com")) .build(); ShareMessengerGenericTemplateElement genericTemplateElement = new ShareMessengerGenericTemplateElement.Builder() .setTitle("Visit Facebook") .setSubtitle("Visit Messenger") .setImageUrl(Uri.parse("heeps://Your/Image/Url")) .setButton(actionButton) .build(); ShareMessengerGenericTemplateContent genericTemplateContent = new ShareMessengerGenericTemplateContent.Builder() .setPageId("Your Page Id") // Your page ID, required .setGenericTemplateElement(genericTemplateElement) .build(); if (MessageDialog.canShow(genericTemplateContent)) { MessageDialog.show(activityOrFragment, genericTemplateContent); }
// Share with mediaURL ShareMessengerMediaTemplateContent mediaTemplateContent = new ShareMessengerMediaTemplateContent.Builder() .setPageId("Your page ID") // Your page ID, required .setMediaType(MediaType.IMAGE) .setMediaUrl(Uri.parse("https://Facebook/Media/URL")) // Must be a Facebook URL, see media template documentation .setButton(actionButton) .build(); if (MessageDialog.canShow(mediaTemplateContent)) { MessageDialog.show(activityOrFragment, mediaTemplateContent); } // Share with attachmentID ShareMessengerMediaTemplateContent mediaTemplateContent = new ShareMessengerMediaTemplateContent.Builder() .setPageId("Your page ID") // Your page ID, required .setMediaType(MediaType.IMAGE) .setAttachmentId("Attachment Id") // AttachmentID, see media template documentation for how to upload an attachment .setButton(actionButton) .build(); if (MessageDialog.canShow(mediaTemplateContent)) { MessageDialog.show(activityOrFragment, mediaTemplateContent); }
ShareMessengerOpenGraphMusicTemplateContent musicTemplateContent = new ShareMessengerOpenGraphMusicTemplateContent.Builder() .setPageId("Your page ID") // Your page ID, required .setUrl(Uri.parse("https://Open/Graph/Music/URL")) // Open graph music url, see open graph music documentation .setButton(actionButton) .build(); if (MessageDialog.canShow(musicTemplateContent)) { MessageDialog.show(activityOrFragment, musicTemplateContent); }