這份文件已更新。
中文(台灣) 的翻譯尚未完成。
英文更新時間:4月22日

Android 的 Instagram 分享到 Reels

本文件說明如何將分享功能整合至 Android 應用程式,方便用戶將圖像、影片和貼圖分享到 Instagram 的 Reels。

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.

實作分享到 Instagram

您可以使用 Explicit Intent(顯示意圖)啟動 Instagram 應用程式並向其傳送 Reels 內容。Instagram 應用程式將接收內容並載入到 Reels 撰寫工具,用戶即可編輯內容並發佈到自己的 Reels。

分享流程通常會執行以下操作:

  1. 實例化 Intent。
  2. 將套件設定為 "com.instagram.android",確保 Instagram 應用程式處理 Intent。
  3. 將您的 Meta 應用程式編號和影音素材內容附加到 Intent。
  4. 實例化 Activity。
  5. 授予 URI 權限,確保 Instagram 可以讀取影音素材內容。
  6. 驗證 Activity 是否可以解析 Intent 並啟動 Activity。

請移除您在用戶裝置上建立的任何暫存檔案。

資料

分享到 Reels 時,應傳送下列資料。

資料說明

Meta 應用程式編號

字串

必要項目。您的 Meta 應用程式編號

影音素材

單一素材為字串

多個素材為清單

必要項目。您需要以下其中一個選項:

  • 圖像的 URI,該圖像為用戶裝置上的本機檔案。可接受的圖像格式:

    • JPG
    • PNG
  • 影片的 URI,該影片為用戶裝置上的本機檔案。影片應符合下列條件:

    • 1080p
    • 時間長度介於 3 到 60 秒之間
    • 可接受的影片格式為 H.264H.265MOVMP4WebM
    • 尺寸不可大於裝置全螢幕
  • 影片和/或圖像的 URI 清單,這些影片和/或圖像為用戶裝置上的本機檔案。

貼圖素材

字串

貼圖的 URI,該貼圖為用戶裝置上的本機檔案。可接受的貼圖格式為 JPGPNG,建議的尺寸為 640 x 480。貼圖會顯示在影片上方。

程式碼範例

下列 Java 和 Kotlin 程式碼範例說明如何傳送單一圖像或影片、如何傳送多個圖像或影片,以及如何傳送包含貼圖的圖像或影片。

使用單一影音素材檔案的範例

下列程式碼範例傳送單一檔案至 Instagram,方便用戶編輯並發佈到自己的 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);
}

使用多個影音素材檔案的範例

下列程式碼範例傳送多個檔案至 Instagram,方便用戶編輯並發佈到自己的 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);
}

包含貼圖的範例

下列程式碼範例傳送影片至 Instagram 並包含一個選用的貼圖,方便用戶編輯並發佈到自己的 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 範例和影片教學導覽

為了方便開發人員作業,Meta 已在 GitHub 上發佈 Instagram 分享到 Reels 的範例程式碼,網址為:fbsamples/share_to_reels_android。請觀看下列影片,瞭解如何使用 GitHub 範例。

發生錯誤
播放此影片時發生問題。