您可將分享功能整合至您的 Android 和 iOS 應用程式,讓用戶可以將您的內容作為 Instagram 限時動態分享。若要建立新應用程式,請參閱開始使用 Facebook Android SDK 和開始使用Facebook iOS SDK。

從 2023 年 1 月開始,您必須提供 Facebook AppID 才能將內容分享到 Instagram 限時動態。如需更多資訊,請參閱Instagram 分享到限時動態的重要更新簡介。如果您未提供 AppID,當用戶嘗試將內容分享到 Instagram 時,會看到錯誤訊息:「您的分享來源應用程式目前不支援分享到限時動態」。如要尋找您的應用程式編號,請參閱取得您的應用程式編號(Android)和取得您的應用程式編號(iOS)。
使用 Android 的隱含內容和 iOS 的自訂網址配置,您的應用程式可將相片、影片和貼圖傳送至 Instagram 應用程式。Instagram 應用程式將接收此內容並載入到限時動態撰寫工具,方便用戶發佈到自己的 Instagram 限時動態。
![]() | Instagram 應用程式的限時動態撰寫工具內含背景圖層和貼圖圖層。 背景圖層背景圖層會填滿畫面,您可以使用相片、影片、單色或顏色漸層自訂背景圖層。 貼圖圖層貼圖圖層可內含圖像,而且用戶可利用限時動態撰寫工具進一步自訂圖層。 |
Android 實作使用隱含意圖來啟動 Instagram 應用程式,並向 Instagram 應用程式傳遞內容。一般來說,您的分享流程應如下所示:
分享至限時動態時將傳送下列資料。
| 內容 | 類型 | 說明 |
|---|---|---|
Facebook 應用程式編號 | 字串 | |
背景素材 | 圖像素材(JPG、PNG)或影片素材(H.264、H.265、WebM)的 URI。最小尺寸為 720x1280。建議的圖像比例為 9:16 或 9:18。影片可以是 1080p,最長可達 20 秒。URI 須為裝置上本機檔案的內容 URI。您必須傳送背景素材、貼圖素材或兩者。 | |
貼圖素材 | 圖像素材(JPG、PNG)的 URI。建議的尺寸:640x480。此圖像將以貼圖形式顯示在背景之上。URI 須為裝置上本機檔案的內容 URI。您必須傳送背景素材、貼圖素材或兩者。 | |
背景圖層頂層顏色 | 字串 | 與背景圖層底色值搭配使用的十六進位字串色彩值。如果兩個值相同,背景圖層將為單色。如果兩個值不同,將用於產生漸層。如果指定背景素材,將使用素材並忽略此值。 |
背景圖層底色 | 字串 | 與背景圖層頂層色彩值搭配使用的十六進位字串色彩值。如果兩個值相同,背景圖層將為單色。如果兩個值不同,將用於產生漸層。如果指定背景素材,將使用素材並忽略此值。 |
下列程式碼範例傳送圖像至 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 應用程式,並向 Instagram 應用程式傳遞內容。一般來說,您的分享流程應如下所示:
分享至限時動態時將傳送下列資料。
| 內容 | 類型 | 說明 |
|---|---|---|
Facebook 應用程式編號 | ||
背景圖像素材 | 支援的圖像素材格式(JPG、PNG)資料。最小尺寸為 720x1280。建議的圖像比例為 9:16 或 9:18。您必須向 Instagram 應用程式傳遞背景素材(圖像或影片)、貼圖素材或兩者。 | |
背景影片素材 | 支援的影片素材格式(H.264、H.265、WebM)資料。影片可以是 1080p,最長可達 20 秒。建議在 50 MB 以下。您必須向 Instagram 應用程式傳遞背景素材(圖像或影片)、貼圖素材或兩者。 | |
貼圖素材 | 支援的圖像素材格式(JPG、PNG)資料。建議的尺寸:640x480。此圖像將以貼圖形式顯示在背景之上。您必須向 Instagram 應用程式傳遞背景素材(圖像或影片)、貼圖素材或兩者。 | |
背景圖層頂層顏色 | 與背景圖層底色值搭配使用的十六進位字串顏色值。如果兩個值相同,背景圖層將為單色。如果兩個值不同,將用於產生漸層。 | |
背景圖層底色 | 與背景圖層底色值搭配使用的十六進位字串顏色值。如果兩個值相同,背景圖層將為單色。如果兩個值不同,將用於產生漸層。 |
您必須註冊 Instagram 的自訂網址配置,您的應用程式才能使用。將 instagram-stories 加入 LSApplicationQueriesSchemes 密鑰(在應用程式的 Info.plist 的中)。
下列程式碼範例傳送背景圖層圖像素材至 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 分享到限時動態說明文件。