Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting video on instagram using hooks

I want my app to be able to upload videos to instagram.

Instagram IPhone Hooks gives information how to use the iphone hooks to upload a photo to instagram. My question is if anyone has any experience on how to accomplish the same but for a video?

like image 828
Nilsymbol Avatar asked Nov 16 '13 10:11

Nilsymbol


2 Answers

Instagram's API doesn't directly support uploading anything from 3rd party applications. Therefore you have to do some ugly user experience compromises when providing the functionality to your users.

First, Prepare the video you want to upload to Instagram and store the path to it somewhere

Second, Save it to the user's Camera Roll:

if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath)) {     UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil); } 

Third, now that the video is saved, tell the user that in order to upload the video to their Instagram, they must select it from their camera roll after clicking the upload button.

The upload button would simply do the following:

NSURL *instagramURL = [NSURL URLWithString:@"instagram://camera"]; if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {     [[UIApplication sharedApplication] openURL:instagramURL]; } 

It's very silly that the Instagram API doesn't support immediate media selection through any of the API endpoints for upload purposes, but as it stands right now, this is the only way.

like image 129
Nico Avatar answered Sep 24 '22 00:09

Nico


I had a similar question: Instagram Video iPhone Hook and I figured it out. There is an undocumented iPhone hook that allows you to automatically select assets from the iPhones photo roll, and preload a caption for the video. This should give you the same user experience that Flipagrams app has with sharing a video to Instagram.

instagram://library?AssetPath=assets-library%3A%2F%2Fasset%2Fasset.mp4%3Fid%3D8864C466-A45C-4C48-B76F-E3C421711E9D%26ext%3Dmp4&InstagramCaption=Some%20Preloaded%20Caption

NSURL *videoFilePath = ...; // Your local path to the video NSString *caption = @"Some Preloaded Caption"; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:videoFilePath] completionBlock:^(NSURL *assetURL, NSError *error) {     NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@",[assetURL absoluteString].percentEscape,caption.percentEscape]];     if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {         [[UIApplication sharedApplication] openURL:instagramURL];     } }]; 
like image 21
johnnyg17 Avatar answered Sep 25 '22 00:09

johnnyg17