文档已更新。
中文(简体) 译文尚未完成。
英语更新时间:3月18日
中文(简体) 更新时间:2月27日

Instagram Sharing to Reels From Android

This document shows you how to integrate sharing into your Android app so that users can share images, videos, and stickers to Reels on Instagram.

Overview

Reels Layers

The Reels composer has a background video layer and an optional sticker layer.

  • Background Video Layer – A video fills the screen
  • Sticker Layer – An optional sticker can appear in front of the video

Sharing Icon

For a consistent user experience across apps, download the standard sharing icon for Instagram Reels and use it in your app.

Before You Start

You will need:

  • A Meta app ID
  • You must Go Live with your Meta app before your app users can share content

Terms and Policies

By accessing and using this functionality, you acknowledge and agree to be bound by the Meta Platform Terms and Developer Policies. You also represent and warrant that any content made available through your application or website, or shared to Instagram Reels from your application or website, does not infringe upon the intellectual property rights of any third party and that you own, control or have otherwise secured all rights necessary to distribute, copy, publicly perform and display, or otherwise use the content via this functionality, including as uploaded and shared on Instagram Reels. You further represent and warrant that you have the authority to make the foregoing representations on behalf of your organization. If you do not have such authority or are otherwise unable to make the foregoing representations, you are not authorized to continue and should not do so.

Implement Sharing to Instagram

You use an Explicit Intent to launch the Instagram app and send it content for Reels. The Instagram app receives the content, loads it in the Reels composer, and the user can edit and publish the content to their Reels.

In general, your sharing flow does the following:

  1. Instantiate an intent.
  2. Set package equal to "com.instagram.android" to ensure that the Instagram app handles the intent.
  3. Attach your Meta App ID and media content to the intent.
  4. Instantiate an activity.
  5. Grant URI permissions to ensure that Instagram can read the media content.
  6. Verify that the activity can resolve the intent and start the activity.

Remove any temporary files that you create on the user's device.

Data

You should send the following data when you share to Reels.

DataDescription

Meta App ID

string

Required. Your Meta app ID

Media Assets

string for a single asset

or

a list for multiple assets

Required. One of the following options is required:

  • The URI for an image that is a local file on the user's device. Acceptable image formats:

    • JPG
    • PNG
  • The URI for a video that is a local file on the user's device. Videos should be:

    • 1080p
    • between 3 and 60 seconds in duration
    • accepted video formats are H.264, H.265, MOV, MP4, and WebM
    • dimensions should be device fullscreen or smaller
  • A list of URIs for videos and/or images that are local files on the user's device.

Sticker Asset

string

The URI for a sticker that is a local file on the user's device. Acceptable sticker formats are JPG and PNG, and the recommended dimensions are 640 x 480. The sticker appears over the video.

Code Examples

The following Java and Kotlin code examples show how to send a single image or video, how to send multiple images or videos, and how to send images or videos with a sticker.

Example with One Media File

The following code example sends a file to Instagram so the user can edit and publish it to their Instagram Reels.

// Instantiate an intent
val intent = Intent("com.instagram.share.ADD_TO_REEL")

// Set package
intent.setPackage("com.instagram.android")

// Attach your App ID to the intent
val appId = "your-app-id"
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId)

// Attach your image or video to the intent from a URI
val mediaAssetUri = Uri.parse("your-image-or-video-asset-uri-goes-here")
intent.setDataAndType(mediaAssetUri, "image/* video/*")
intent.putExtra(Intent.EXTRA_STREAM, mediaAssetUri)

// Instantiate an activity
val activity: Activity = getActivity()

// Grant URI permissions
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val resInfoList = activity.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
for (resolveInfo in resInfoList) {
    val packageName = resolveInfo.activityInfo.packageName
    activity.grantUriPermission(packageName, mediaAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

// Verify that the activity resolves the intent and start it
if (activity.packageManager.resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0)
}
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_REEL");

// Set package
intent.setPackage("com.instagram.android");

// Attach your App ID to the intent
String appId = "your-app-id";
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId);

// Attach your image or video to the intent from a URI
Uri mediaAssetUri = Uri.parse("your-image-or-video-asset-uri-goes-here");
intent.setDataAndType(mediaAssetUri, "image/* video/*");
intent.putExtra(Intent.EXTRA_STREAM, mediaAssetUri);

// Instantiate an activity
Activity activity = getActivity();

// Grant URI permissions
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    activity.grantUriPermission(packageName, mediaAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0);
}

Example with Multiple Media Files

The following code example sends multiple files to Instagram so the user can edit and publish them to their Instagram Reels.

// Instantiate an intent
val intent = Intent("com.instagram.share.ADD_TO_REEL_MULTIPLE")

// Set package
intent.setPackage("com.instagram.android")

// Attach your App ID to the intent
val appId = "your-app-id"
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId)
intent.setType("image/* video/*")

// Attach your files to the intent
val uri1 = Uri.parse("your-first-uri-goes-here")
val uri2 = Uri.parse("your-second-uri-goes-here")
val mediaList = mutableListOf<Uri>()
mediaList.addAll(listOf(uri1, uri2))
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, ArrayList(mediaList))

// Instantiate an activity
val activity: Activity = getActivity()

// Grant URI permissions
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val resInfoList =
activity.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
for (uri in mediaList) {
  for (resolveInfo in resInfoList) {
    val packageName = resolveInfo.activityInfo.packageName
    activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
  }
}

// Verify that the activity resolves the intent and start it
if (activity.packageManager.resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0)
}
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_REEL_MULTIPLE");

// Set package
intent.setPackage("com.instagram.android");

// Attach your App ID to the intent
String appId = "your-app-id";
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId);
intent.setType("image/* video/*");

// Attach your files to the intent
Uri uri1 = Uri.parse("your-first-uri-goes-here");
Uri uri2 = Uri.parse("your-second-uri-goes-here");
ArrayList<Uri> mediaList = new ArrayList<>();
mediaList.add(uri1);
mediaList.add(uri2);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, mediaList);

// Instantiate an activity
Activity activity = getActivity();

// Grant URI permissions
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (Uri uri : mediaList) {
    for (ResolveInfo resolveInfo : resInfoList) {
        String packageName = resolveInfo.activityInfo.packageName;
        activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    }
}

// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0);
}

Example with Sticker

The following code example sends a video to Instagram, and includes an optional sticker, so the user can edit and publish it to their Instagram Reels.

// Instantiate an intent
val intent = Intent("com.instagram.share.ADD_TO_REEL")

// Set package
intent.setPackage("com.instagram.android")

// Attach your App ID to the intent
val appId = "your-app-id" 
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId)

// Attach your video to the intent from a URI
val videoAssetUri = Uri.parse("your-video-asset-uri-goes-here")
intent.setDataAndType(videoAssetUri, "video/*")
intent.putExtra(Intent.EXTRA_STREAM, videoAssetUri)

// Attach your sticker to the intent from a URI
val stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here")
intent.putExtra("interactive_asset_uri", stickerAssetUri)

// Instantiate an activity
val activity: Activity = getActivity()

// Grant URI permissions
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val resInfoList = activity.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY)
for (resolveInfo in resInfoList) {
    val packageName = resolveInfo.activityInfo.packageName
    activity.grantUriPermission(packageName, videoAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
    activity.grantUriPermission(packageName, stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

// Verify that the activity resolves the intent and start it
if (activity.packageManager.resolveActivity(intent, 0) != null) {
    activity.startActivityForResult(intent, 0)
}
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_REEL");

// Set package
intent.setPackage("com.instagram.android");

// Attach your App ID to the intent
String appId = "your-app-id";
intent.putExtra("com.instagram.platform.extra.APPLICATION_ID", appId);

// Attach your video to the intent from a URI
Uri videoAssetUri = Uri.parse("your-video-asset-uri-goes-here");
intent.setDataAndType(videoAssetUri, "video/*");
intent.putExtra(Intent.EXTRA_STREAM, videoAssetUri);

// Attach your sticker to the intent from a URI
Uri stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here");
intent.putExtra("interactive_asset_uri", stickerAssetUri);

// Instantiate an activity
Activity activity = getActivity();

// Grant URI permissions
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
    String packageName = resolveInfo.activityInfo.packageName;
    activity.grantUriPermission(packageName, videoAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
    activity.grantUriPermission(packageName, stickerAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
  activity.startActivityForResult(intent, 0);
}

GitHub Sample and Video Tutorial

To make it more convenient for developers, Meta has published sample code for Instagram Share to Reels on GitHub at fbsamples/share_to_reels_android. Watch the following video to learn how to use the GitHub Sample.

发生错误
播放视频时出错