Post to Instagram

I am working on an application where I need to post an image / video on instagram. I successfully posted an image on Instagram with the following code:

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]; } 

But I did not find a way to publish the video on it. I checked the Instagram app and found that we can send and upload videos. This means that with code this should be possible. Does anyone know about this?

Thanks in advance.

+7
ios objective-c instagram
source share
3 answers

Try this code to post a video on instagram this works for me, hope this works for you too.

first you need to save the video in Cameraroll and then use

 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]; } 
+2
source share

After deprecating ALAssetLibrary, Instagram also disabled the AssetPath parameter. Now you can use the localIndentifier property of the local PHAsset for this case.

  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: this works fine for me, but it is still not documented anywhere.

+1
source share

Nice to know how Instagram works. The code is really helpful. Video marketing takes up about 60% of Instagram and is a very good way to get more involved. IGTV is also a great opportunity for Instagram users to have a broader engagement with their audience. You can upload videos of long duration and share your work. I found this blog that is easy and useful to start using IGTV features. https://instagramlogins.net/how-to-post-videos-on-igtv/

0
source share

All Articles