Skip to content

Instantly share code, notes, and snippets.

@stelabouras
Last active March 18, 2021 22:38
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stelabouras/1634b0c3ef080a0aa733 to your computer and use it in GitHub Desktop.
Save stelabouras/1634b0c3ef080a0aa733 to your computer and use it in GitHub Desktop.
Loads a Camera Roll Asset to Instagram (works for both photos & videos)
- (void)loadCameraRollAssetToInstagram:(NSURL*)assetsLibraryURL andMessage:(NSString*)message
{
NSString *escapedString = [assetsLibraryURL.absoluteString urlencodedString];
NSString *escapedCaption = [message urlencodedString];
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library?AssetPath=%@&InstagramCaption=%@", escapedString, escapedCaption]];
[[UIApplication sharedApplication] openURL:instagramURL];
}
@gabrielribeiro
Copy link

InstagramCaption is not working on my code. When it opens Instagram, it shows no caption. Even if I use a single word with no space or special chars.

@pjrfigueiredo
Copy link

Since August 2015 that you can't.

Beginning today, the iOS Hooks and Android Intents will stop accepting captions passed by third party apps. (...) Instagram will ignore the caption text. To create a caption for a photo or video shared by a third party app, users will have to enter a caption manually, the same way they already do when sharing content using the Instagram native apps.

http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing

@mlagadhir
Copy link

this code do not show photo anymore into Instagram app, any idea?
NSString *caption2 = @"wertheclay";
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:self.image.CGImage metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
NSURL *instagramURL = [NSURL URLWithString:[NSString stringWithFormat:@"instagram://library AssetPath=%@&InstagramCaption=%@", assetURL, caption2]];
NSLog(@"assetURL %@", assetURL);
[[UIApplication sharedApplication] openURL:instagramURL];

}];

@chetem
Copy link

chetem commented Apr 12, 2016

i'm having the same issue @mlagadhir, the url is not working.

let fileURLString = url.absoluteString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
let encodedURLString = "instagram://library?AssetPath=\(fileURLString)"
guard let encodedURL = NSURL(string:encodedURLString) else { print("failed to create instagram url") }

This fails to create the url for instagram every time. have you had any luck?

@omarojo
Copy link

omarojo commented Jul 27, 2016

instagram://library?AssetPath=(assetsLibraryUrl) stopped working a while ago. Instagram developers probably moved to Photos framework and no longer use the AssetsLibrary.

Having this assumption I tried several other parameter names and found that instagram://library?LocalIdentifier=(localID) where localId is the localIdentifier of your PHAsset works for now.

This is still as undocumented as it was so it can break in any future version of the Instagram.

@yjb94
Copy link

yjb94 commented Feb 27, 2017

instagram://library?LocalIdentifier=(localID)

stopped working...

@ericleiyang
Copy link

instagram://library?LocalIdentifier=(localID) stopped working for me as well

@ricardopereira
Copy link

LocalIdentifier works for me.

@dorshorst
Copy link

Using an unescaped local identifier along with the URL param OpenInEditor=1 seems to get it working again, at least currently.

Example: instagram://library?OpenInEditor=1&LocalIdentifier=DBD74ED9-4D9D-4F35-B12A-5B647944DDFE/L0/001

@adamhaafiz
Copy link

adamhaafiz commented Jul 27, 2017

instagram://library?AssetPath=\(fileURLString) starting crashing for me all of a sudden, changing to instagram://library?OpenInEditor=1&LocalIdentifier=\(fileLocalIdString) works.

@dhomes
Copy link

dhomes commented Jan 23, 2018

is there a way from preventing it showing the POST TO FEED / STORY that started showing up recently? I'd like to go directly to my feed

@innoranveer
Copy link

I am facing the same issue the image which i want to share from app isn't landing on Instagram image editor, its forcing me to choose photo from library or camera

@roimulia
Copy link

roimulia commented Feb 8, 2018

Same issue as @innoravaneer

@Jaydip-iOS
Copy link

Thanks and i need same thing working for whatsapp Also so please can you share code for whatsApp ?

@AFathi
Copy link

AFathi commented May 21, 2018

@DavidAPears
Copy link

`instagram://library?OpenInEditor=1&LocalIdentifier=+${encodedURL}`; 

Worked for me :)

@rewaant
Copy link

rewaant commented Nov 26, 2020

Stopped working now. Any other way to do this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment