【发布时间】:2018-12-03 15:36:42
【问题描述】:
如何将视频作为背景和图像作为贴纸一起分享到 Instagram 快拍?
如果两个内容都是图像,则此文档只有一个解决方案。
https://developers.facebook.com/docs/instagram/sharing-to-stories/
我想发送背景视频和贴纸图片。 Instagram Story 可以做到吗?
我试过了,可惜没用:
// Define image asset URI and attribution link URL
Uri backgroundAssetUri = Uri.fromFile(new File(backgroundPath));
Uri stickerAssetUri = Uri.fromFile(new File(stickerPath));
// Instantiate implicit intent with ADD_TO_STORY action,
// background asset, and attribution link
Intent intent = new Intent("com.instagram.share.ADD_TO_STORY");
intent.setDataAndType(backgroundAssetUri, "*/*");
intent.putExtra("interactive_asset_uri", stickerAssetUri);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
callbackManager.startActivityForResult(Intent.createChooser(intent, "Share"), NatShareCallbacks.ACTIVITY_SHARE_INSTAGRAM_STORY);
但是带有两张图片的示例可以正常工作。我主要看到 SetType 的问题,因为它们是两种不同的内容类型。
[编辑]
没有贴纸的单独视频已经在 Android 上对我有用,并且带有图像背景和图像贴纸的文档示例也可以完美运行。但不能同时使用视频和贴纸。
它在iOS下运行没有任何问题:
NSData *backgroundVideo = [[NSFileManager defaultManager] contentsAtPath:path];
UIImage *appIcon = [UIImage imageNamed: [[[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectForKey:@"CFBundlePrimaryIcon"] objectForKey:@"CFBundleIconFiles"] objectAtIndex:0]];
// Verify app can open custom URL scheme, open
NSURL *urlScheme = [NSURL URLWithString:@"instagram-stories://share"];
if ([[UIApplication sharedApplication] canOpenURL:urlScheme]) {
// Assign background image asset and attribution link URL to pasteboard
//NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundVideo" : backgroundVideo}];
NSArray *pasteboardItems = @[@{@"com.instagram.sharedSticker.backgroundVideo" : backgroundVideo, @"com.instagram.sharedSticker.stickerImage" : UIImagePNGRepresentation(appIcon)}];
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 older app versions or app not installed case
}
【问题讨论】:
-
告诉我你的视频文件名
-
你试过用 image/* 作为类型吗
-
@RutvikBhatt 没有贴纸的单独视频已经为我工作了。所以它不应该是视频路径。
-
@ImtiyazKhalani 我得到一个“image/*”异常 - 12-12 12:22:19.551 2559 2830 E AndroidRuntime 致命异常:IgExecutor #12 - 12-12 12:22:19.551 2559 2830 E AndroidRuntime 进程:com.instagram.android,PID:2559 - 12-12 12:22:19.551 2559 2830 E AndroidRuntime java.lang.RuntimeException: 无效图像。
标签: android facebook android-intent instagram instagram-api