您可以将分享功能集成到 Android 和 iOS 应用,以便用户可以将您的内容以 Instagram 快拍的形式进行分享。要新建应用,请参阅 Android 版 Facebook SDK 入门指南和 iOS 版 Facebook 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。您必须发送一个背景素材和/或一个贴图素材。 | |
背景层顶部颜色 | 字符串 | 与背景层底部颜色值结合使用的十六进制字符串颜色值。如果二者相同,则背景层将为纯色。如果二者不同,则将用于生成渐变色。如果您指定了背景素材,系统将使用该素材,而忽略此值。 |
背景层底部颜色 | 字符串 | 与背景层顶部颜色值结合使用的十六进制字符串颜色值。如果二者相同,则背景层将为纯色。如果二者不同,则将用于生成渐变色。如果您指定了背景素材,系统将使用该素材,而忽略此值。 |
以下示例代码将向 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 应用传送一个背景素材(图片或视频)和/或一个贴图素材。 | |
背景层顶部颜色 | 与背景层底部颜色值结合使用的十六进制字符串颜色值。如果二者相同,则背景层将为纯色。如果二者不同,则将用于生成渐变色。 | |
背景层底部颜色 | 与背景层底部颜色值结合使用的十六进制字符串颜色值。如果二者相同,则背景层将为纯色。如果二者不同,则将用于生成渐变色。 |
您需要注册 Instagram 的自定义网址方案,您的应用才能使用此方案。将 instagram-stories 添加到您应用的 Info.plist 中的 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 分享到快拍文档。