您可以將分享功能整合至 Android 和 iOS 應用程式,以便用戶將內容分享到 Instagram 限時動態。若要建立新應用程式,請參閱 Facebook Android SDK 新手指南和 Facebook iOS SDK 新手指南。

由 2023 年 1 月起,您必須提供 Facebook 應用程式編號才能將內容分享到 Instagram 限時動態。詳情請參閱 Instagram 分享到限時動態功能推出重要更新一文。如您不提供應用程式編號,您的用戶將在嘗試將其內容分享至 Instagram 時,看到「你用於分享內容的應用程式目前不支援分享至限時動態」的錯誤訊息。若要查看您的應用程式編號,請參閱如何獲取您的應用程式編號(Android)和獲取您的應用程式編號(iOS)。
您可以使用 Android 的隱含意圖和 iOS 的自訂網址配置,讓您的應用程式能夠將相片、影片和貼圖傳送至 Instagram 應用程式。Instagram 應用程式會接收此等內容,並在限時動態編輯器中加以載入,以便用戶將其發佈至自己的 Instagram 限時動態。
![]() | Instagram 應用程式的限時動態編輯器包含背景圖層與貼圖圖層。 背景圖層背景圖層將會填滿畫面,而您可以使用相片、影片、淨色或漸變顏色自訂背景圖層。 貼圖圖層貼圖圖層可以含有圖像,而且用戶可以在限時動態編輯器中進一步自訂圖層。 |
Android 建置會使用隱含意圖,以啟動 Instagram 應用程式並向其傳送內容。一般而言,您的分享流程應如下所示:
您可以在將內容分享到限時動態時傳送下列資料。
| 內容 | 類型 | 說明 |
|---|---|---|
Facebook 應用程式編號 | 字串 | 您的 Facebook 應用程式編號。 |
背景素材 | 圖像素材(JPG、PNG)或影片素材(H.264、H.265、WebM)的 URI。尺寸最小可為 720x1280。建議圖片比例為 9:16 或 9:18。影片解像度可為 1080p,最長為 20 秒。此 URI 需要是裝置本機檔案的內容 URI。您必須傳送背景素材、貼圖素材或同時傳送兩者。 | |
貼圖素材 | 圖像素材(JPG、PNG)的 URI。推薦尺寸: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 建置會使用自訂網址配置,以啟動 Instagram 應用程式並向其傳送內容。一般而言,您的分享流程應如下所示:
您可以在將內容分享到限時動態時傳送下列資料。
| 內容 | 類型 | 說明 |
|---|---|---|
Facebook 應用程式編號 | 您的 Facebook 應用程式編號。 | |
背景圖像素材 | 採用支援格式(JPG、PNG)的圖像素材資料。尺寸最小可為 720x1280。建議圖片比例為 9:16 或 9:18。您必須向 Instagram 應用程式傳送背景素材(圖像或影片)、貼圖素材或同時傳送兩者。 | |
背景影片素材 | 採用支援格式(H.264、H.265、WebM)的影片素材資料。影片解像度可為 1080p,最長為 20 秒。建議大小不超過 50 MB。您必須向 Instagram 應用程式傳送背景素材(圖像或影片)、貼圖素材或同時傳送兩者。 | |
貼圖素材 | 採用支援格式(JPG、PNG)的圖像素材資料。推薦尺寸:640x480。此圖像會以貼圖形式加在背景上。您必須向 Instagram 應用程式傳送背景素材(圖像或影片)、貼圖素材或同時傳送兩者。 | |
背景圖層頂部顏色 | 與背景圖層底部顏色值一同使用的 16 進制字串顏色值。如果這兩個值相同,背景圖層將會是淨色。如果這兩個值不同,則會用於產生漸層效果。 | |
背景圖層底部顏色 | 與背景圖層底部顏色值一同使用的 16 進制字串顏色值。如果這兩個值相同,背景圖層將會是淨色。如果這兩個值不同,則會用於產生漸層效果。 |
您需要先登記 Instagram 的自訂網址配置,然後您的應用程式才能加以使用。在您應用程式的 Info.plist 中,將 instagram-stories 加為 LSApplicationQueriesSchemes 密鑰。
下列程式碼範例會將背景圖層圖像素材傳送至 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 分享至限時動態文件。