2014-03-31 55 views
7

我正在开发应用程序,我需要在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

试试这个代码张贴在Instagram的 它为我希望它为你的作品也

首先你必须将视频保存到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

这仍然适合你吗? – user3344977

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:这适用于我,但它仍然没有记录在任何地方。