分享到动态
借助“分享到动态”,您可以让应用用户将您的内容分享到自己的 Instagram 动态中。

Android 开发者
如要在 Android 上实现此功能,请使用带有 EXTRA_STREAM extra 的隐式意图提示用户选择 Instagram 应用。选中后,该意图将启动 Instagram 应用并向其传送您的内容,随后 Instagram 应用便会在动态编辑器中加载此内容。
一般而言,您的分享流程应该是:
- 使用您要传送至 Instagram 应用的内容对隐式意图进行实例化。
- 开始某项活动并检查它是否可以解析隐式意图。
- 如果能够进行解析,请解析此活动。
可分享的内容
您可以将下列内容传送至 Instagram 应用:
| 内容 | 文件类型 | 说明 |
|---|---|---|
图片素材 | JPEG、GIF 或 PNG | - |
文件素材 | MKV、MP4 | 最短时长:3 秒 最长时长:10 分钟 最小尺寸:640x640 像素 |
分享图片素材
String type = 'image/*';String filename = '/myPhoto.jpg';String mediaPath = Environment.getExternalStorageDirectory() + filename;createInstagramIntent(type, mediaPath);private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, 'Share to'));}分享视频素材
String type = 'video/*';String filename = '/myVideo.mp4';String mediaPath = Environment.getExternalStorageDirectory() + filename;createInstagramIntent(type, mediaPath);private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, 'Share to'));}iOS 开发者
iOS 实现可使用通用链接启动 Instagram 应用并向其传送内容,或让其执行特定操作。
通用链接
使用下表列出的通用链接在 Instagram 应用中执行操作。
| 通用链接 | 操作 |
|---|---|
https://www.instagram.com | 启动 Instagram 应用。 |
https://www.instagram.com/create/story | 启动 Instagram 应用并打开相机视图;若是没有相机的设备,则打开照片库。 |
https://www.instagram.com/p/{media_id} | 启动 Instagram 应用并加载与指定编号值 ( |
https://www.instagram.com/{username} | 启动 Instagram 应用并加载与指定帐号值 ( |
https://www.instagram.com/explore/locations/{location_id} | 启动 Instagram 应用并加载与指定编号值 ( |
https://www.instagram.com/explore/tags/{tag_name} | 启动 Instagram 应用并加载与指定名称值 ( |
Objective-C 代码示例
以下 Objective-C 代码示例在启动 Instagram 应用时打开了相机视图。
NSURL *instagramURL = [NSURL URLWithString:@'https://www.instagram.com/create/story'];if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];}文档交互
如果您的应用程序创建了照片,且您想让用户使用 Instagram 分享这些照片,则可使用文档交互 API,在 Instagram 的分享流程中打开照片。
您必须先以 PNG 或 JPEG(首选)格式保存文件,并使用文件扩展名 .ig。通过使用 iOS 文档交互 API,您可以触发 Instagram 打开照片的操作。我们的文档交互 UTI 标识符为 com.instagram.photo,而且其符合 public/jpeg 和 public/png UTI。详情请参阅 Apple 文档文章:Previewing and Opening Files(预览和打开文件)以及 UIDocumentInteractionController Class Reference(UIDocumentInteractionController 类参考文档)。
或者,如果您希望在应用程序列表中仅显示 Instagram(而非 Instagram 和任何其他符合 public/jpeg 的应用),则可指定扩展类 igo(其属于 com.instagram.exclusivegram 类型)。
一经触发,Instagram 会立即向用户呈现我们的滤镜屏幕。系统将以适合 Instagram 的方式预载图片并调整图片大小。为提供最佳效果,Instagram 会优先选择打开尺寸为 640x640 像素的正方形 JPEG 图片。如果图片较大,系统会动态调整其尺寸。

