使用挂钩在Instagram上发布视频

Nil*_*bol 38 video objective-c ios instagram

我希望我的应用能够将视频上传到Instagram.

Instagram IPhone Hooks提供了如何使用iphone挂钩将照片上传到instagram的信息.我的问题是,是否有人有任何经验,如何完成相同但视频?

Nic*_*nen 44

Instagram的API不直接支持从第三方应用程序上传任何内容.因此,在向用户提供功能时,您必须做出一些丑陋的用户体验妥协.

首先,准备要上传到Instagram的视频并将路径存储到某个地方

其次,将其保存到用户的相机胶卷:

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath)) {
    UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
}
Run Code Online (Sandbox Code Playgroud)

第三,既然保存了视频,告诉用户为了将视频上传到他们的Instagram,他们必须在点击上传按钮后从他们的相机胶卷中选择它.

上传按钮只会执行以下操作:

NSURL *instagramURL = [NSURL URLWithString:@"instagram://camera"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [[UIApplication sharedApplication] openURL:instagramURL];
}
Run Code Online (Sandbox Code Playgroud)

Instagram API不支持通过任何API端点立即选择媒体进行上传,这是非常愚蠢的,但就目前而言,这是唯一的方法.

  • 虽然公开发布的文档没有提及它,但确实有一种方法可以启动Instagram,预先选择照片或视频并准备进行编辑.长话短说,你可以做一些像这样的`instagram://库?AssetPath = [CAMERA ROLL URL]和InstagramCaption = [MESSAGE]`,其中两个参数必须是url编码的.我在这里描述[我们博客中的整个过程](http://blog.horizo​​n.camera/post/102273431070/video-share-objc-ios-instagram). (16认同)

joh*_*g17 20

我有一个类似的问题:Instagram视频iPhone Hook,我想通了.有一个未记录的iPhone挂钩,允许您从iPhone照片卷自动选择资源,并预加载视频的标题.这应该为您提供Flipagrams应用程序与Instagram共享视频时的相同用户体验.

的Instagram://库AssetPath =资产库%3A%2F%2Fasset%2Fasset.mp4%3Fid%3D8864C466-A45C-4C48-B76F-E3C421711E9D%26ext%3Dmp4&InstagramCaption =有些%20Preloaded%20Caption?

NSURL *videoFilePath = ...; // Your local path to the video
NSString *caption = @"Some Preloaded Caption";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoFilePath] completionBlock:^(NSURL *assetURL, NSError *error) {
    NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",[assetURL absoluteString].percentEscape,caption.percentEscape]];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
        [[UIApplication sharedApplication] openURL:instagramURL];
    }
}];
Run Code Online (Sandbox Code Playgroud)


小智 10

尝试:

instagram://library?AssetPath=yourVideoPath
Run Code Online (Sandbox Code Playgroud)

我发现这里的解决方案:http://blog.horizo​​n.camera/post/102273431070/video-share-objc-ios-instagram


Sta*_*mes 5

针对iOS 9进行了更新.

首先,对于iOS9,您需要添加到您的Info.plist文件中.添加LSApplicationQueriesSchemes带有值的键a instagram.这将使Instagram计划列入白名单.更多信息在这里.

这是基于johnnyg17的工作代码:

NSString *moviePath = @"<# /path/to/movie #>";
NSString *caption = @"<# Your caption #>";
NSURL *movieURL = [NSURL fileURLWithPath:moviePath isDirectory:NO];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:movieURL
                            completionBlock:^(NSURL *assetURL, NSError *error)
{
    NSURL *instagramURL = [NSURL URLWithString:
                           [NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",
                            [[assetURL absoluteString] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]],
                            [caption stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet alphanumericCharacterSet]]]
                           ];
    if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
        [[UIApplication sharedApplication] openURL:instagramURL];
    }
    else {
        NSLog(@"Can't open Instagram");
    }
}];
Run Code Online (Sandbox Code Playgroud)

样本instagramURL将是:

instagram://library?AssetPath=assets%2Dlibrary%3A%2F%2Fasset%2Fasset%2Emov%3Fid%3D69920271%2D2D44%2D4A84%2DA373%2D13602E8910B6%26ext%3Dmov&InstagramCaption=Super%20Selfie%20Dance%20%F0%9F%98%83

更新2016/5:请注意,ALAssetsLibrary现在已弃用以保存到用户相册,现在推荐使用照片框架.


cod*_*cat -3

您可以通过媒体端点完成

https://api.instagram.com/v1/media/3?access_token=ACCESS-TOKEN
Run Code Online (Sandbox Code Playgroud)

获取有关媒体对象的信息。返回的类型键将允许您区分图像和视频媒体。

http://instagram.com/developer/endpoints/media/

此链接用于获取图像媒体 ID。但我希望同样的技术对视频有帮助。

在哪里可以找到图片的 Instagram 媒体 ID

NSURL *instagramURL = [NSURL URLWithString:@"instagram://media?id=315"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    [[UIApplication sharedApplication] openURL:instagramURL];
}
Run Code Online (Sandbox Code Playgroud)

优势信息:

  1. instagram://camera 将打开相机或照片库(取决于设备),
  2. instagram://app 将打开该应用程序
  3. instagram://user?username=foo 将打开该用户名
  4. instagram://location?id=1 将打开该位置
  5. instagram://media?id=315 将打开该媒体

  • 媒体 ID 仅与已上传到 Instagram 的媒体相关。 (6认同)