Uploading photos to Instagram via your own iOS app

Instagram recently made a change to their API policy which allowed developers to post pictures to the Instagram platform via their own app. Several other techniques we’re previously employed to do this. One of them was to invoke the Instagram application which would essentially open up Instagram and do the sharing from there. A tutorial on how this can be done can be seen here: How to share image to Instagram from your own iOS app

However there are several applications out there that allow for direct sharing to the Instagram platform without invoking the Instagram application. Hipstamatic’s Oggl allows for direct sharing to Instagram without invoking Instagram. Below I have posted some screen shots of the process.

  • Find if current time is between a range
  • How to create own mask in ios
  • CoreData: error: (14) I/O error for database
  • iOS: Delete ALL Core Data Swift
  • delegate function vs callback function
  • UIImagePickerController on iPad with IOS9
  • Once my picture was taken, Oggl gave me several other social networks to which I could share my photo to. I’ve selected Facebook and Instagram.

    enter image description here

    After I selected Instagram, it opened up Safari and it brought me to the following two pages to authorize Oggl to post to Instagram. I entered in my Instagram credentials and then it brought me to the authorization page.

    enter image description here enter image description here

    Once I authorized Oggl, I was able to upload to Instagram and within seconds, I saw the photo on my Instagram news feed. This type of sharing is very analogous to Facebook and Twitter sharing. It has the same concept. How can one go about doing this? How can one replicate this exact process in their app? The pictures taken in my application are 612px by 612 px, so they are compatible with the dimensions for photos taken on Instagram. I’ve already implemented sharing to Facebook and Twitter but I would like to implement uploading to Instagram just like how Oggl did. Is this possible?

    There are many iOS developers out there who can benefit from a well detailed canonical answer to this question.

    Thank You

    7 Solutions Collect From Internet About “Uploading photos to Instagram via your own iOS app”

    Hipstamatic are one of the few apps that has been given write access via Instagram’s API.

    Instagram doesn’t have a public API for posting photos, it lets you get their data but not write your own.

    Hipstamatic and several other apps have negotiated special deals with Instagram that allow them to use the write API and post photos directly.

    For all other developers you need to use iOS hooks to share to Instagram by switching to their app.

    As far as I know its not easy to get Instagram to allow you write access- you would need to have a top app with high quality content and be friendly with the right people 🙂

    You can not directly post an image on Instagram. You have to redirect your image with UIDocumentInteractionController. Use Below code , Hope It will help

    @property (nonatomic, retain) UIDocumentInteractionController *dic;    
    CGRect rect = CGRectMake(0 ,0 , 0, 0);
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
    self.dic.UTI = @"com.instagram.photo";
    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 {
         UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
         interactionController.delegate = interactionDelegate;
         return interactionController;

    What you are trying to do is implemented through the Instagram API http://instagram.com/developer/. You can also use the Instagram App to do some similar actions. These are documented under iPhone Hooks. If you are using Ruby Motion, then you will be able to use the official framework. Unfortunately, there is no officially supported Objective-C iOS API but some open source alternatives are available, like the NRGramKit.

    The exact way of implementing the interaction with the Instagram API is beyond a Stack Overflow answer but the links above should give you a good starting point if you are familiar with iOS programming.

    verbatim from the Instagram API documentation:


    At this time, uploading via the API is not possible. We made a conscious choice not to add this for the following reasons:

    1. Instagram is about your life on the go – we hope to encourage photos from within the app.
    2. We want to fight spam & low quality photos. Once we allow uploading from other sources, it’s harder to control what comes into the Instagram ecosystem. All this being said, we’re working on ways to ensure users have a consistent and high-quality experience on our platform.

    if you want to just send the image without clipping you should set image size of 640 x 640 or the application crash

    This my swift code

     var instagramURL = NSURL(string: "instagram://app")!
            if UIApplication.sharedApplication().canOpenURL(instagramURL) {
                var documentDirectory = NSHomeDirectory().stringByAppendingPathComponent("Documents")
                var saveImagePath = documentDirectory.stringByAppendingPathComponent("Image.igo")
                var imageData = UIImagePNGRepresentation(self.bestScoreShareView.takeSnapshot(W: 640, H: 640))
                imageData.writeToFile(saveImagePath, atomically: true)
                var imageURL = NSURL.fileURLWithPath(saveImagePath)!
               docController  = UIDocumentInteractionController()
                docController.delegate = self
                docController.UTI = "com.instagram.exclusivegram"
                docController.URL = imageURL
                docController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)
            } else {
                println("instagram not found")

    extension for take shapshot from uiview

    extension UIView {
        func takeSnapshot(#W: CGFloat, H: CGFloat) -> UIImage {
            var cropRect = CGRectMake(0, 0, 600, 600)
            UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.mainScreen().scale)
            drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
            let image = UIGraphicsGetImageFromCurrentImageContext()
            image.imageWithNewSize(CGSizeMake(W, H))
            return image

    extension for set image size

    extension UIImage {
         func imageWithNewSize(newSize:CGSize) ->UIImage {
            self.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height))
            let newImage = UIGraphicsGetImageFromCurrentImageContext();
            return newImage

    You may also want to check out the “Document Interaction” section of Instagram’s API documentation for iPhone Hooks. This could be leveraged to do what you are trying to do and it might be the way Oggl does it.

    I have used below code for sharing photo in Instagram.

        NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
        if([[UIApplication sharedApplication] canOpenURL:instagramURL]) //check for App is install or not
            NSData *imageData = UIImagePNGRepresentation(image); //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()];
            NSString *fileNameToSave = [NSString stringWithFormat:@"Documents/insta.igo"];
            NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:fileNameToSave];
            NSLog(@"jpg path %@",jpgPath);
            NSString *newJpgPath = [NSString stringWithFormat:@"file://%@",jpgPath];
            NSLog(@"with File path %@",newJpgPath);
            NSURL *igImageHookFile = [[NSURL alloc]initFileURLWithPath:newJpgPath];
            NSLog(@"url Path %@",igImageHookFile);
            self.documentController.UTI = @"com.instagram.exclusivegram";
           // self.documentController = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
            self.documentController=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
            NSString *caption = @"#Your Text"; //settext as Default Caption
            self.documentController.annotation=[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@",caption],@"InstagramCaption", nil];
            [self.documentController presentOpenInMenuFromRect:rect inView: self.view animated:YES];
            UIAlertView *errMsg = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"No Instagram Available" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
            [errMsg show];