AndroidとiOSアプリにシェア機能を統合し、ユーザーがコンテンツをInstagramストーリーズにシェアできるようにします。新しいアプリを作成するには、Android用Facebook SDKスタートガイドとiOS用Facebook SDKスタートガイドをご覧ください。

2023年1月より、InstagramストーリーズにコンテンツをシェアするにはFacebook AppIDを提供する必要があります。詳細については、Instagramのストーリーズへのシェアに重大なアップデートを導入をご覧ください。AppIDを提供していない場合、ユーザーがInstagramにコンテンツをシェアしようとしたときに「あなたがシェアしたアプリは現在ストーリーズへのシェアをサポートしていません」というエラーメッセージが表示されます。アプリIDを探すには、アプリIDの取得(Android)とアプリIDの取得(iOS)をご覧ください。
Androidの暗黙的インテントとiOSのカスタムURLスキームを使って、アプリから写真、動画やスタンプをInstagramアプリに送ることができます。Instagramアプリはコンテンツを受け取ってストーリーズコンポーザーに読み込み、ユーザーがInstagramストーリーズで公開できるようにします。
![]() | Instagramアプリのストーリーズコンポーザーは、バックグラウンドレイヤーとスタンプレイヤーで構成されています。 バックグラウンドレイヤーバックグラウンドレイヤーはスクリーンを埋めるもので、写真、動画、ソリッドカラーやグラデーションカラーでカスタマイズできます。 スタンプレイヤースタンプレイヤーには画像を入れられます。ユーザーはストーリーズコンポーザー内でスタンプレイヤーをさらにカスタマイズすることができます。 |
Androidに実装する場合、暗黙的インテントを使ってInstagramアプリを起動し、コンテンツを渡します。通常のコンテンツ共有の流れは以下の通りです。
ストーリーズでシェアすると、以下のデータを送信します。
| コンテンツ | 型 | 説明 |
|---|---|---|
FacebookアプリID | 文字列 | |
バックグラウンドアセット | URIで指定して画像アセット(JPG、PNG)または動画アセット(H.264、H.265、WebM)を生成。最大サイズ720x1280。推奨画像比9:16または9:18。動画は1080p、最長20秒まで対応URIはデバイス上のローカルファイルへのコンテンツURIにする必要があります。バックグラウンドアセット、スタンプレイヤー、またはその両方を送信しなければなりません。 | |
スタンプアセット | URIで指定して画像アセット(JPG、PNG)を生成。推奨画像サイズ: 640x480。この画像はスタンプとしてバックグラウンドに表示されます。URIはデバイス上のローカルファイルへのコンテンツURIにする必要があります。バックグラウンドアセット、スタンプレイヤー、またはその両方を送信しなければなりません。 | |
バックグラウンドレイヤーのトップカラー | 文字列 | バックグラウンドレイヤーのボトムカラー値と併せて使用される16進数のカラー値。トップカラーとボトムカラーが同じ値である場合は、バックグラウンドレイヤーはソリッドカラーになります。異なる値である場合は、グラデーションカラーとなります。バックグラウンドアセットを指定した場合、アセットが使用されてこの値は無視されます。 |
バックグラウンドレイヤーのボトムカラー | 文字列 | バックグラウンドレイヤーのトップカラー値と併せて使用される16進数のカラー値。トップカラーとボトムカラーが同じ値である場合は、バックグラウンドレイヤーはソリッドカラーになります。異なる値である場合は、グラデーションカラーとなります。バックグラウンドアセットを指定した場合、アセットが使用されてこの値は無視されます。 |
次のコードサンプルは、画像をInstagramに送信してユーザーが自分のInstagramストーリーズに公開できるようにするものです。
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
// Attach your App ID to the intent
String sourceApplication = "1234567"; // This is your application's FB ID
intent.putExtra("source_application", sourceApplication);
// Attach your image to the intent from a URI
Uri backgroundAssetUri = Uri.parse("your-image-asset-uri-goes-here");
intent.setDataAndType(backgroundAssetUri, MEDIA_TYPE_JPEG);
// Grant URI permissions for the image
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// Instantiate an activity
Activity activity = getActivity();
// Verify that the activity resolves the intent and start it
if (activity.getPackageManager().resolveActivity(intent, 0) != null) {
activity.startActivityForResult(intent, 0);
} このサンプルは、スタンプレイヤー画像アセットと一連のバックグラウンドレイヤーカラーをInstagramに送信します。バックグラウンドレイヤーカラーを指定しない場合、バックグラウンドレイヤーカラーは#222222になります。
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
// Attach your App ID to the intent
String sourceApplication = "1234567"; // This is your application's FB ID
intent.putExtra("source_application", sourceApplication);
// Attach your sticker to the intent from a URI, and set background colors
Uri stickerAssetUri = Uri.parse("your-image-asset-uri-goes-here");
intent.setType(MEDIA_TYPE_JPEG);
intent.putExtra("interactive_asset_uri", stickerAssetUri);
intent.putExtra("top_background_color", "#33FF33");
intent.putExtra("bottom_background_color", "#FF00FF");
// Instantiate an activity
Activity activity = getActivity();
// Grant URI permissions for the sticker
activity.grantUriPermission(
"com.instagram.android", 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);
}このサンプルは、バックグラウンドレイヤー画像アセットとスタンプレイヤー画像アセットをInstagramに送信します。
// Instantiate an intent
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
// Attach your App ID to the intent
String sourceApplication = "1234567"; // This is your application's FB ID
intent.putExtra("source_application", sourceApplication);
// Attach your image to the intent from a URI
Uri backgroundAssetUri = Uri.parse("your-background-image-asset-uri-goes-here");
intent.setDataAndType(backgroundAssetUri, MEDIA_TYPE_JPEG);
// Attach your sticker to the intent from a URI
Uri stickerAssetUri = Uri.parse("your-sticker-image-asset-uri-goes-here");
intent.putExtra("interactive_asset_uri", stickerAssetUri);
// Grant URI permissions for the image
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
// Instantiate an activity
Activity activity = getActivity();
// Grant URI permissions for the sticker
activity.grantUriPermission(
"com.instagram.android", 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);
}iOSに実装する場合は、カスタムURLスキームを使ってInstagramアプリを起動し、コンテンツを渡します。通常のコンテンツ共有の流れは以下の通りです。
ストーリーズでシェアすると、以下のデータを送信します。
| コンテンツ | 型 | 説明 |
|---|---|---|
FacebookアプリID | ||
バックグラウンド画像アセット | サポートされているフォーマット(JPG、PNG)での画像アセットのデータ。最大サイズ720x1280。推奨画像比9:16または9:18。Instagramアプリにバックグラウンドアセット(画像または動画)、スタンプアセット、またはその両方を渡す必要があります。 | |
バックグラウンド動画アセット | サポートされているフォーマット(H.264、H.265、WebM)での動画アセットのデータ。動画は1080p、最長20秒まで対応50MB以下を推奨。Instagramアプリにバックグラウンドアセット(画像または動画)、スタンプアセット、またはその両方を渡す必要があります。 | |
スタンプアセット | サポートされているフォーマット(JPG、PNG)での画像アセットのデータ。推奨画像サイズ: 640x480。この画像はスタンプとしてバックグラウンドに表示されます。Instagramアプリにバックグラウンドアセット(画像または動画)、スタンプアセット、またはその両方を渡す必要があります。 | |
バックグラウンドレイヤーのトップカラー | バックグラウンドレイヤーのボトムカラー値と併せて使用される16進数のカラー値。トップカラーとボトムカラーが同じ値である場合は、バックグラウンドレイヤーはソリッドカラーになります。異なる値である場合は、グラデーションカラーとなります。 | |
バックグラウンドレイヤーのボトムカラー | バックグラウンドレイヤーのボトムカラー値と併せて使用される16進数のカラー値。トップカラーとボトムカラーが同じ値である場合は、バックグラウンドレイヤーはソリッドカラーになります。異なる値である場合は、グラデーションカラーとなります。 |
InstagramのカスタムURLスキームをアプリで使用するには、事前にスキームを登録する必要があります。アプリのInfo.plistのLSApplicationQueriesSchemesキーにinstagram-storiesを追加します。
次のコードサンプルは、バックグラウンドレイヤー画像アセットをInstagramに送信して、ユーザーが編集したり自分のInstagramストーリーズに公開したりできるようにします。
- (void)shareBackgroundImage
{
// Identify your App ID
NSString *const appIDString = @"1234567890";
// Call method to share image
[self backgroundImage:UIImagePNGRepresentation([UIImage imageNamed:@"backgroundImage"])
appID:appIDString];
}
// Method to share image
- (void)backgroundImage:(NSData *)backgroundImage
appID:(NSString *)appID
{
NSURL *urlScheme = [NSURL URLWithString:[NSString stringWithFormat:@"instagram-stories://share?source_application=%@", appID]];
if ([[UIApplication sharedApplication] canOpenURL:urlScheme])
{
// Attach the pasteboard items
NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundImage" : backgroundImage}];
// Set pasteboard options
NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
// This call is iOS 10+, can use 'setItems' depending on what versions you support
[[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];
[[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
}
else
{
// Handle error cases
}
} このサンプルコードは、Instagramアプリにスタンプレイヤー画像アセットと一連のバックグラウンドレイヤーのカラーを渡す方法を示します。バックグラウンドレイヤーカラーを指定しない場合、バックグラウンドレイヤーカラーは#222222になります。
- (void)shareStickerImage
{
// Identify your App ID
NSString *const appIDString = @"1234567890";
// Call method to share sticker
[self stickerImage:UIImagePNGRepresentation([UIImage imageNamed:@"stickerImage"])
backgroundTopColor:@"#444444"
backgroundBottomColor:@"#333333"
appID:appIDString];
}
// Method to share sticker
- (void)stickerImage:(NSData *)stickerImage
backgroundTopColor:(NSString *)backgroundTopColor
backgroundBottomColor:(NSString *)backgroundBottomColor
appID:(NSString *)appID
{
NSURL *urlScheme = [NSURL URLWithString:[NSString stringWithFormat:@"instagram-stories://share?source_application=%@", appID]];
if ([[UIApplication sharedApplication] canOpenURL:urlScheme])
{
// Attach the pasteboard items
NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.stickerImage" : stickerImage,
@"com.instagram.sharedSticker.backgroundTopColor" : backgroundTopColor,
@"com.instagram.sharedSticker.backgroundBottomColor" : backgroundBottomColor}];
// Set pasteboard options
NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
// This call is iOS 10+, can use 'setItems' depending on what versions you support
[[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];
[[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
}
else
{
// Handle error cases
}
}このサンプルコードは、Instagramアプリにバックグラウンドレイヤーの画像アセットとスタンプレイヤーの画像アセットを渡す方法を示します。
- (void)shareBackgroundAndStickerImage
{
// Identify your App ID
NSString *const appIDString = @"1234567890";
// Call method to share image and sticker
[self backgroundImage:UIImagePNGRepresentation([UIImage imageNamed:@"backgroundImage"])
stickerImage:UIImagePNGRepresentation([UIImage imageNamed:@"stickerImage"])
appID:appIDString];
}
// Method to share image and sticker
- (void)backgroundImage:(NSData *)backgroundImage
stickerImage:(NSData *)stickerImage
appID:(NSString *)appID
{
NSURL *urlScheme = [NSURL URLWithString:[NSString stringWithFormat:@"instagram-stories://share?source_application=%@", appID]];
if ([[UIApplication sharedApplication] canOpenURL:urlScheme])
{
// Attach the pasteboard items
NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundImage" : backgroundImage,
@"com.instagram.sharedSticker.stickerImage" : stickerImage}];
// Set pasteboard options
NSDictionary *pasteboardOptions = @{UIPasteboardOptionExpirationDate : [[NSDate date] dateByAddingTimeInterval:60 * 5]};
// This call is iOS 10+, can use 'setItems' depending on what versions you support
[[UIPasteboard generalPasteboard] setItems:pasteboardItems options:pasteboardOptions];
[[UIApplication sharedApplication] openURL:urlScheme options:@{} completionHandler:nil];
}
else
{
// Handle error cases
}
}アプリのユーザーにコンテンツをFacebookのストーリーズとしてシェアすることを許可することもできます。許可する方法については、Facebookのストーリーズへのシェアに関するドキュメントをご覧ください。