AndroidからInstagramリールへのシェア

このドキュメントでは、ユーザーがInstagramリールに画像、動画、スタンプをシェアできるように、Androidアプリにシェア機能を統合する方法について示します。


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へのシェア機能の実装

Instagramアプリを起動してそれにリールのコンテンツを送信するには、明示的インテントを使います。Instagramアプリはコンテンツを受け取ってそれをリールコンポーザーに読み込み、ユーザーがそのコンテンツを編集してリールに公開します。

シェアの一般的なフローは、以下のとおりです。

  1. インテントをインスタンス化する。
  2. パッケージが"com.instagram.android"と等しくなるように設定することにより、Instagramアプリがインテントを処理するようにする。
  3. MetaアプリIDとメディアコンテンツをインテントにアタッチする。
  4. アクティビティをインスタンス化する。
  5. Instagramがメディアコンテンツを読めるように、URIアクセス許可を付与する。
  6. アクティビティがインテントを解決し、アクティビティを開始できることを確認する。

ユーザーのデバイス上に作成した一時ファイルを削除する。

データ

リールにシェアする際には、以下のデータを送信してください。

データ説明

MetaアプリID

文字列

必須。MetaアプリID

メディアアセット

文字列(単一アセットの場合)

または

リスト(複数アセットの場合)

必須。以下のオプションのいずれか1つが必要です。

  • ユーザーのデバイス上のローカルファイルである画像のURI。使用可能な画像フォーマット:

    • JPG
    • PNG
  • ユーザーのデバイス上のローカルファイルである動画のURI。動画は次のようにしてください。

    • 1080p
    • 長さ3~60秒
    • 使用可能な動画フォーマット: H.264H.265MOVMP4WebM
    • ディメンションはデバイスのフルスクリーン以下
  • ユーザーのデバイス上のローカルファイルである動画や画像のURIのリスト。

スタンプアセット

文字列

ユーザーのデバイス上のローカルファイルであるスタンプのURI。使用可能なスタンプのフォーマットはJPGPNGであり、推奨ディメンションは640×480です。スタンプは動画の上に重ねて表示されます。

コードの例

次のJavaおよびKotlinのコードサンプルは、単一の画像または動画の送信方法、複数の画像または動画の送信方法、スタンプを付けた画像または動画の送信方法を示しています。

メディアファイルが1個の例

次のコードサンプルでは、Instagramに1個のファイルを送信し、ユーザーがそれを編集してInstagramリールに公開できるようにしています。

// 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リールに公開できるようにしています。

// 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に1個の動画を送信し、任意のスタンプを含め、ユーザーがそれを編集して自分のInstagramリールに公開できるようにしています。

// 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はInstagramリールへのシェア機能のサンプルコードをGitHubで公開しています。これは、fbsamples/share_to_reels_androidにあります。GitHubサンプルの使い方については、次の動画をご覧ください。

エラーが発生しました
エラーが発生し、この動画を再生できませんでした。