在Instagram上发布视频

时间:2014-03-31 08:31:12

标签: ios objective-c instagram

我正在开发应用程序,我需要在Instagram上发布图像/视频。我已经成功地使用以下代码在Instagram上发布图像:

        NSString* filename = [NSString stringWithFormat:@"myimage.igo"];
        NSString* savePath = [imagesPath stringByAppendingPathComponent:filename];
        [UIImagePNGRepresentation(myImage) writeToFile:savePath atomically:YES];
        NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
        {
            self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
            self.documentInteractionController.UTI = @"com.instagram.image";
            self.documentInteractionController.delegate = self;
            [self.documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
        }

但是没有找到任何方式将视频发布到它上面。我检查了Instagram应用程序,发现我们也可以发布/上传视频。它意味着通过代码它应该是可能的。有人知道吗?

提前致谢。

2 个答案:

答案 0 :(得分:2)

尝试使用此代码在Instagram上发布视频 它对我有用希望它也适合你

首先你必须保存Video To Cameraroll然后使用这个

NSString *strURL = [NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",yourfilepath,yourCaption];
NSString* webStringURL = [strURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* instagramURL = [NSURL URLWithString:webStringURL];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL])
{
[[UIApplication sharedApplication] openURL:instagramURL];
}

答案 1 :(得分:1)

在ALAssetLibrary弃用后,Instagram也禁用了AssetPath参数。 现在,您可以使用PHAsset localIndentifier的localIndentifier属性。

   NSURL *instagramURL  = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?LocalIdentifier=%@", placeholderForCreatedAsset.localIdentifier]];
        [[UIApplication sharedApplication] openURL:instagramURL];
        if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
            [[UIApplication sharedApplication] openURL:instagramURL];
        }

PS:这对我来说很好,但是在任何地方都没有记录。

相关问题