从我的iOS应用程序分享照片到Instagram

ayo*_*yon 3 objective-c sharing ios instagram

我一直在寻找一种方式,从我正在开发的iOS应用程序发布照片到Instagram.但是看到一些链接,似乎他们不支持使用他们的API进行写访问.所以,

  1. 是否可以通过某些API或Instagram API从iOS分享照片到Instagram?
  2. 如果可能,任何人都可以建议我做一个教程或文档吗?

他们的api说这个......

"目前,无法通过API上传.我们有意识地选择不添加此内容,原因如下:

Instagram是关于你在旅途中的生活 - 我们希望鼓励应用程序内的照片.但是,将来我们可能会根据具体情况授予白名单访问个人应用程序的权限.我们想要打击垃圾邮件和低质量的照片.一旦我们允许从其他来源上传,就很难控制Instagram生态系统中的内容.所有这些都说明了,我们正在努力确保用户在我们的平台上获得一致和高质量的体验."

这就是为什么我在寻找更好的建议.

在此先感谢您的帮助.

Nit*_*itk 11

请在设备中尝试此代码....共享在模拟器中不起作用

它会将图像从应用程序保存到文档目录,它将共享相同的图像到instagram.

对于分享,我将只采用.igo格式

-(void)shareInInstagram
{
  NSData *imageData = UIImagePNGRepresentation(imge); //convert image into .png format.

    NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it

    NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"insta.igo"]]; //add our image to the path

    [fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)

    NSLog(@"image saved");


    CGRect rect = CGRectMake(0 ,0 , 0, 0);
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIGraphicsEndImageContext();
    NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"];
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave];
    NSLog(@"jpg path %@",jpgPath);
    NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath]; //[[NSString alloc] initWithFormat:@"file://%@", jpgPath] ];
    NSLog(@"with File path %@",newJpgPath);
    NSURL *igImageHookFile = [[NSURL alloc] initFileURLWithPath:newJpgPath];
    NSLog(@"url Path %@",igImageHookFile);

    self.dic.UTI = @"com.instagram.exclusivegram";
    self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
    self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    [self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];


}



- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {
    NSLog(@"file url %@",fileURL);
    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    interactionController.delegate = interactionDelegate;

    return interactionController;
}
Run Code Online (Sandbox Code Playgroud)