我一直在寻找一种从我正在开发的iOS应用程序将照片发布到Instagram的方法。但看到一些链接,他们似乎不支持使用API进行写访问。所以,
- 是否可以通过某些API或Instagram API将照片从iOS共享到Instagram
- 如果可能的话,有人能给我推荐一个教程或文档吗
他们的api是这样说的。。。
"目前,通过API上传是不可能的。我们有意识地选择不添加,原因如下:
Instagram是关于你在旅途中的生活——我们希望鼓励在应用程序中拍摄照片。然而,在未来,我们可能会根据具体情况为个别应用程序提供白名单访问权限。我们要打击垃圾邮件&低质量的照片。一旦我们允许从其他来源上传,就很难控制进入Instagram生态系统的内容。话虽如此,我们正在努力确保用户在我们的平台上获得一致和高质量的体验。"
这就是为什么我在寻找更好的建议。
提前感谢您的帮助。
请在设备中尝试此代码。。。。共享在模拟器中不起作用
它将把应用程序中的图像保存到文档目录中,并将相同的图像共享到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;
}