The unofficial Instagram iOS SDK

Overview

InstagramKit

CI Status Version License Platform

Carthage compatible Apps Using Downloads Twitter: @bhatthead

An extensive Objective C wrapper for the Instagram API, completely compatible with Swift.

Here's a quick example to retrieve trending media on Instagram:

InstagramEngine *engine = [InstagramEngine sharedEngine];
[engine getPopularMediaWithSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) {
// media is an array of InstagramMedia objects
...
} failure:^(NSError *error, NSInteger statusCode) {
...
}];

The framework is built atop AFNetworking’s blocks-based architecture and additionally, parses JSON data and creates model objects asynchronously so there’s absolutely no parsing on the main thread. It’s neat, fast and works like a charm.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

InstagramKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'InstagramKit'

If your App uses authorization and you'd like the storage and retrieval of the access token in the Keychain to be automatically handled for you by UICKeyChainStore, include the following lines instead -

pod 'InstagramKit'
pod 'InstagramKit/UICKeyChainStore'

InstagramKit uses UICKeyChainStore as an optional sub-dependency for Keychain access. If you opt to use the optional pod, InstagramKit resumes your authenticated sessions across App launches, without needing any additional code.

Instagram Developer Registration

Head over to http://instagram.com/developer/clients/manage/ to register your app with Instagram and set the right credentials for InstagramAppClientId and InstagramAppRedirectURL in your App's Info.plist file.

InstagramAppClientId is your App's Client Id and InstagramAppRedirectURL, the redirect URI which is obtained on registering your App on Instagram's Developer Dashboard. The redirect URI specifies where Instagram should redirect users after they have chosen whether or not to authenticate your application.

Instagram Platform Updates

Instagram frequently updates its APIs and deprecates endpoints that are in use. If you see a 400 or other strange errors from the server response, please check on Instagram's API changelog and create an issue with your findings. https://www.instagram.com/developer/changelog/

Usage

Authentication

For each API call, you will need an Access Token and specific scope permissions. To get the Access Token, the user needs to authenticate your app to access his Instagram account with the specified permissions.

To do so, redirect the user to https://instagram.com/oauth/authorize/?client_id=[Client ID]&redirect_uri=[Redirect URI]&response_type=token or allow InstagramEngine's helper method do the hard work for you -

NSURL *authURL = [[InstagramEngine sharedEngine] authorizationURL];
[self.webView loadRequest:[NSURLRequest requestWithURL:authURL]];

Scopes

All apps have basic read access by default, but if you plan on asking for extended access such as liking, commenting, or managing friendships, you need to specify these scopes in your authorization request using the InstagramKitScope enum.

Note that in order to use these extended permissions, first you need to submit your app for review to Instagram.

For your app to POST or DELETE likes, comments or follows, you must apply to Instagram here : https://www.facebook.com/help/instagram/contact/185819881608116#

// Set scope depending on permissions your App has been granted from Instagram
// InstagramKitLoginScopeBasic is included by default.

InstagramKitLoginScope scope = InstagramKitLoginScopeRelationships | InstagramKitLoginScopeComments | InstagramKitLoginScopeLikes; 

NSURL *authURL = [[InstagramEngine sharedEngine] authorizationURLForScope:scope];
[self.webView loadRequest:[NSURLRequest requestWithURL:authURL]];

Once the user grants your app permission, they will be redirected to a url in the form of something like http://localhost/#access_token=[access_token] and [access_token] will be split by a period like [userID].[rest of access token]. InstagramEngine includes a helper method to validate this token.

UIWebView
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSError *error;
if ([[InstagramEngine sharedEngine] receivedValidAccessTokenFromURL:request.URL error:&error]) {
// success!
...
}
return YES;
}
WKWebView
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler
{   
NSError *error;
if ([[InstagramEngine sharedEngine] receivedValidAccessTokenFromURL:navigationAction.request.URL error:&error]) {
// success!
...
}    
decisionHandler(WKNavigationActionPolicyAllow);
}

Authenticated Requests

Once you're authenticated and InstagramKit has been provided an accessToken, it will automatically persist it until you call -logout on InstagramEngine. An authenticated call looks no different:

InstagramEngine *engine = [InstagramEngine sharedEngine];
[engine getSelfRecentMediaWithSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) {
// media is an array of InstagramMedia objects
...
} failure:^(NSError *error, NSInteger statusCode) {
...
}];

Pagination

The InstagramPaginationInfo object has everything it needs to make your next pagination call.

If you need to make fetch a paginated feed of results, use the variation of the method which accepts count and maxId as parameters. For instance, use getMediaForUser:count:maxId:withSuccess:failure: passing the next maxID to the maxId parameter each time, obtained from paginationInfo.nextMaxId of the newest paginationInfo object.

[engine getMediaForUser:user.Id 
count:15 
maxId:self.currentPaginationInfo.nextMaxId 
withSuccess:^(NSArray *media, InstagramPaginationInfo *paginationInfo) 
{
if (paginationInfo) {
self.currentPaginationInfo = paginationInfo;
}
...
} 
failure:^(NSError *error) 
{
...
}];

The first request will go with maxId as nil.

Each endpoint in the Instagram API that supports pagination, usually supports a count parameter. You can use this method and pass a count parameter to each paginated request. You can also use it in cases where you do not need pagination, but need to specify a feed count to the first request.

Read in detail about more ways of implementing Pagination for your requests effortlessly in the Pagination Wiki.

Contributions?

Glad you asked. Check out the open Issues and jump right in.

Questions?

The Instagram API Documentation is your definitive source of information in case something goes wrong. Please make sure you've read up the documentation before posting issues.

Author

Shyam Bhat, [email protected] Twitter: @bhatthead

License

InstagramKit is available under the MIT license. See the LICENSE file for more info.

==================

InstagramKit uses the public Instagram API and is not affiliated with either Instagram or Facebook.

Comments
  • {

    {"code":400,"error_type":"OAuthException","error_message":"Redirect URI does not match registered redirect URI"} "

    I just run your example project.I am confused what we have to put in InstagramKitAppRedirectURL.I tried so many things but still i am getting this error.

    First i put Redirect URI whenever i register my application. Second I put Redirect_URI/#access_token=. Third I put client_id//authorize Pls tell me if i am wrong.

    invalid question 
    opened by rajat100919021 14
  • Stopped working

    Stopped working

    for some reason my likes stopped working today. no code changing or anything everything was working fine. I tested the demo and it had the same problem.

    opened by claytoncohn 14
  • the example project does not compile

    the example project does not compile

    after doing pod install for the library and the example project, there is a build error when trying to compile it with XCode 7 (the error is something like: -ipods not found ...)

    please check out the project for errors.

    opened by murad1981 12
  • Externalize Configuration

    Externalize Configuration

    Currently, it seems that it is necessary to modify the header "InstagramEngine.h". This solution isn't ideal as it requires you to modify pods managed files, which could get over-written accidentally. This change allows you to specify the credentials in an externalized plist file, or in the application's info plist file.

    The new plist configuration keys are as follows:

    • InstagramKitAppClientId - the client ID
    • InstagramKitAppRedirectUrl - the app redirect URL
    • InstagramKitBaseUrl - the base URL for the API (if left blank this uses a default value)
    • InstagramKitInstagramKitAuthorizationUrl - the base URL for OAuth via Instagram (if left blank this uses a default value)

    You can specify these keys in either the Application's info.plist file, or you can use a separate configuration file "Instagram.plist" and just leave it in the bundle. It will detect which is used when the InstagramEngine is initialized.

    I tested this with the demo application as well as changed the demo application's code to use the changes. I did my best to avoid breaking existing code and favored using __deprecated where necessary.

    opened by ptwohig 9
  • Login not working.

    Login not working.

    Hi, I Installed IK as a cocoapod, and tried to implement login like in the demo, with a webview, but I get a compilation error, that IKLoginScope not found. I tried the LoginWithBlock function as well, but that takes to the browser outside the application, and after logging in on the website, it takes me to the redirect uri, but does not return control to the application.

    Please help. Thanks MK

    opened by manishkungwani 8
  • Redirect URL not found

    Redirect URL not found

    Hi I have downloaded your zip file and I replaced my instagram credentials. But I could not run the application. I have used different URL's as part of Redirect URL but still problem persists. please bear with me in this and let me finish login with instagram. Thanks in advance...

    opened by narasimhanallamsetty 8
  • Fixed crash for missing full_name in InstagramUser

    Fixed crash for missing full_name in InstagramUser

    Instagram seemed to have restricted access to certain properties and they have dropped the full_name in some cases. For instance when requesting: GET /users/self/media/recent/ the users_in_photos property only has username and no full_name anymore.

    opened by stremsdoerfer 7
  • Terminating app due to uncaught exception 'NSInternalInconsistencyException'

    Terminating app due to uncaught exception 'NSInternalInconsistencyException'

    Nice and thanks!! But I have some problem form the demo When I run the demo in xcode, it will black screen and return following error.

    2014-04-02 09:31:46.835 InstagramKit[5181:60b] *** Assertion failure in -[InstagramEngine init], /Users/louisyip/Downloads/InstagramKit-master 2/InstagramKit/Engine/InstagramEngine.m:115 2014-04-02 09:31:46.839 InstagramKit[5181:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid Instagram Client ID.'

    Would you please tell me which part I wrong?

    opened by louisyip 7
  • InstagramMedia get comments count returns zero.

    InstagramMedia get comments count returns zero.

    Hi

    You wrote the following code to get comments count and it's comment. Most of the time kData is not available and we can get only comments count. But

    NSDictionary *commentsDictionary = info[kComments];
            self.mComments = [[NSMutableArray alloc] init];
            if ([commentsDictionary isKindOfClass:[NSDictionary class]]) {
               **// KData is not available.**
                for (NSDictionary *commentInfo in commentsDictionary[kData]) { 
                    InstagramComment *comment = [[InstagramComment alloc] initWithInfo:commentInfo];
                    [self.mComments addObject:comment];
                }
                **// kCount is available.**
                NSNumber *commentsCount = commentsDictionary[kCount];
                self.commentsCount = commentsCount.integerValue;
            }
    
    

    In the following getter method, you used mComments array count for getting the media's comments count. Instead of that, Can you please use "self.commentsCount" variable which will give us the perfect result..

    - (NSInteger)commentCount
    {
        return [self.mComments count]; 
    }
    

    https://github.com/shyambhat/InstagramKit/edit/master/InstagramKit/Models/InstagramMedia.m

    opened by vigneshuvi 6
  • receivedValidAccessTokenFromURL return nothing in Swift framework

    receivedValidAccessTokenFromURL return nothing in Swift framework

    Hello,

    I'm trying to convert the example from the readme, in Swift but I think there is a problem with the framework in Swift for the receivedValidAccessTokenFromURL function. The function should return a bool, but it returns nothing. Here the public function as I can see it : public func receivedValidAccessTokenFromURL(url: NSURL) throws I guess it should be : public func receivedValidAccessTokenFromURL(url: NSURL) throws -> Bool

    I use the last version of instagramKit (3.7) from Cocoapods.

    Thank you

    opened by MaximeChaillou 6
  • Carthage support

    Carthage support

    The repo readme file says: Carthage support But adding the following to my cartfile:

    github "shyambhat/InstagramKit" == 3.6.9
    

    Gives the following error:

    Dependency "InstagramKit" has no shared framework schemes
    
    If you believe this to be an error, please file an issue with the maintainers at https://github.com/shyambhat/InstagramKit/issues/new
    
    opened by nicolaidahl 6
  • Login Flow issue

    Login Flow issue

    Hi need to implement Instagram login in my app. Earlier I am using your InstagramEngine framework. But these are deprecated now a days, so I have installed this instgramkit, with old methods I have replaced with new instagramkit methods. But I could not login, IKLoginViewControler getting issue. Can you explain how to get user details. My app just need user details, not required any other details. is this will work for new Instagram display API, any effect while sending build to App Store. Can you explain hoot use login and get user details with latest methods please. or any one?

    Thanks in advance.

    opened by muga87 0
  • [question] instagram fingerprint

    [question] instagram fingerprint

    I would like to mock a real instagram app fingerprint in my project by fingerprint i mean device_id, adid phone_id uuiddoes anyone know which file instagram app persist these fields? so i can read it from a real phone (rooted)

    opened by bolds07 0
  • How can I get the 10 most popular user publications in a certain time?

    How can I get the 10 most popular user publications in a certain time?

    Hello! For example, I want to get the 10 most popular user publications in 2 years, I want to determine popularity by the likes' number. is it possible?

    opened by alexanderkhitev 0
Releases(4.0)
  • 4.0(Jun 3, 2018)

  • 3.8(Mar 21, 2016)

  • 3.7(Dec 9, 2015)

    • Complete Swift compatibility.
    • #179 Add Nullability and Lightweight Generics for Xcode 7. By @Adlai-Holler
    • Unit tests for Media and User methods in InstagramEngine. By @shyambhat
    • #177 Fix issue with pagination. Avoid percent-encoding twice. By @snoonz
    Source code(tar.gz)
    Source code(zip)
  • 3.6.9(Oct 19, 2015)

    Added

    • Xcode 7 changes to Project file.
    • Added CHANGELOG.md

    Changed

    • -getMediaAtLocation: count: maxId: withSuccess: failure: changed to -getMediaAtLocation: count: maxId: distance: withSuccess: failure:
    • #167 Typo fixed -authorizarionURL to authorizationURL. By @natan.

    Fixed

    • #146 Checks for media URLs in initializing InstagramMedia objects.
    • #148 Fix Token Get in Authorisation scopes. By @DanTakagaki.
    • #164 InstagramModel copyWithZone updated to allocate correct type of object. By @urklc.
    • #165 Parameter Count must be larger than zero. Fixes #150. By @shyambhat
    Source code(tar.gz)
    Source code(zip)
  • 3.6.8(Aug 26, 2015)

  • 3.6.7(Aug 26, 2015)

  • 3.6.6(Aug 21, 2015)

    Additions :

    • Persisting access token using UICKeyChainStore. UICKeyChainStore is added as an optional sub-spec.
    • Discontinued support for iOS 6, to comply with AFNetworking's compatible SDKs.
    • Added - authorizarionURL helper method to InstagramEngine to generate Authorization URL with basic permissions.

    Changes :

    • - extractValidAccessTokenFromURL renamed to - receivedValidAccessTokenFromURL
    • - getUserDetails: withSuccess: failure: accepts a string value for userId to maintain consistency.

    Fixes :

    • Call super encode/decode on subclasses of InstagramModel to keep ID property persisted Implemented by @natan in #140
    Source code(tar.gz)
    Source code(zip)
  • 3.6.5(Jul 13, 2015)

    • Documentation and comments.
    • Model objects implement the NSSecureCoding Protocol and can be persisted.
    • Access token is (finally) persisted in NSUserDefaults.
    Source code(tar.gz)
    Source code(zip)
  • 3.6.4(Jul 7, 2015)

    Authentication made simpler; removed misleading and unnecessary authentication methods. Completely rewritten InstagramKit-Example project. Restructured Project with Cocoapods.

    Source code(tar.gz)
    Source code(zip)
  • 3.6.3(May 26, 2015)

  • 3.6.2(May 26, 2015)

  • 3.6.1(May 26, 2015)

  • 3.6.0(May 26, 2015)

    • Removed dependence on external InstagramKit.plist file for Credentials.
    • Location Endpoints added by @adamjuhasz in #103.
    • Equality of Instagram Model Objects, by @adonoho in #95.
    • Optimised for iPhone 6 / 6+ by @MPieter in #101.
    • Lots of refactoring. Thanks @ribeto #105.
    Source code(tar.gz)
    Source code(zip)
  • 3.5.0(Jun 9, 2014)

    InstagramKit now includes methods to -

    • Get a list of followers and following.
    • Get follow status of other users.
    • Follow, unfollow, block, unblock, approve or deny other users.
    Source code(tar.gz)
    Source code(zip)
  • 3.1.1(Apr 3, 2014)

  • 3.1.0(Apr 1, 2014)

    This release includes an complete overhaul of the each endpoint request to provide seamless pagination options. We've taken some tough decisions to discontinue support for previous versions for the better and it's strongly recommended that you upgrade to this version at the earliest and take care of signature changes.

    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Feb 22, 2014)

  • 1.1.0(Feb 2, 2014)

    Everything works as it's supposed to.

    Endpoints for likes and comments are functional.

    Minor Changes in method definitions from previous versions. Please review your header file in case of migration from previous version.

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0-beta(Feb 1, 2014)

Owner
Shyam Bhat
Shyam Bhat
Unofficial Dribbble iOS wrapper allows you to integrate Dribble API into iOS application (Designer, Shot, Comment, User Story, Like, Follow)

DribbbleSDK DribbbleSDK is easy-to-use iOS wrapper for Dribbble SDK. We're working hard to complete the full coverage of available methods and make th

Agilie Team 74 Dec 2, 2020
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
Wanikani-swift - Unofficial Swift client for the WaniKani API

WaniKani A Swift library and client for the WaniKani REST API. It currently supp

Aaron Sky 5 Oct 28, 2022
Instagram API client written in Swift

SwiftInstagram is a wrapper for the Instagram API written in Swift. It allows you to authenticate users and request data from Instagram effortlessly.

Ander Goig 579 Dec 31, 2022
The Waterwheel Swift SDK provides classes to natively connect iOS, macOS, tvOS, and watchOS applications to Drupal 7 and 8.

Waterwheel Swift SDK for Drupal Waterwheel makes using Drupal as a backend with iOS, macOS, tvOS, or watchOS enjoyable by combining the most used feat

Kyle Browning 414 Jul 26, 2022
This repository is for the new ARGear SDK library for the iOS platform

This repository is for the new ARGear SDK library for the iOS platform. The library is not official yet. The library will be updated frequently by applying user feedback. When the APIs are fixed, the official library will be released.

ARGear 2 Apr 5, 2022
A swift SDK for Medium's OAuth2 API

Medium SDK - Swift A library to allow access to Medium API for any Swift iOS application. Features Medium.com authorization & token handling Login sta

null 11 Jan 22, 2022
Giphy API client for iOS in Objective-C

Giphy-iOS Giphy-iOS is a Giphy API client for iOS in Objective-C. Usage To run the example project, clone the repo, and run pod install from the Examp

alex choi 52 Jul 11, 2019
The Easiest and Simplest iOS library for Twitter and Facebook. Just Drop in and Use!

EasySocial iOS Library for Twitter and Facebook This library allows your apps to use Twitter and Facebook with minimal understanding of the relevant S

pj 124 Nov 17, 2022
A Swift wrapper for Foursquare API. iOS and OSX.

Das Quadrat Das Quadrat is Foursquare API wrapper written in Swift. Features Supports iOS and OSX. Covers all API endpoints. Authorization process imp

Constantine Fry 171 Jun 18, 2022
A Twitter framework for iOS & OS X written in Swift

Getting Started Installation If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own pr

Matt Donnelly 2.4k Dec 30, 2022
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
Easy and powerful way to interact with VK API for iOS and macOS

Easy and powerful way to interact with VK API for iOS and macOS. Key features ?? It's not ios-vk-sdk ?? ?? One library for iOS and mac OS ?? ?? Fully

null 260 Dec 22, 2022
iOS/macOS Cross-platform Ark-Ecosystem Framework in Swift | Powered by Ѧrk.io |

a macOS & iOS Swift Framework for Ark.io. What is ARKKit? ARKKit is wrapper for interacting with the Ark Ecosystem. It is written purely in Swift 4.0,

Simon 19 Jun 28, 2022
Twitter Clone for iOS With Swift

Postwitter Date: December 1, 2021 Product Name: Postwitter Problem Statement: iO

Shohin Abdulkhamidov 3 Aug 16, 2022
Studio Ghibli Movie database in Swift. For iOS, iPadOS, and MacOS.

Ghibliii Studio Ghibli Movie database in Swift *Colours are shifted due to compression About This started as a way for me to do something in this quar

Kevin Laminto 19 Dec 9, 2022
Easy Proximity-based Bluetooth LE Sharing for iOS

Description Easy Proximity-based Sharing for iOS Perfect for any iOS app that needs to quickly share items with nearby friends, such as groups, photo

Laura Skelton 132 Aug 10, 2022
Instagram clone, the main focus of the app is the seamless swipe between views that we see on instagram

InstaSwipe Instagram clone, the main focus of the app is the seamless swipe betw

Stavros Pachoundakis 1 Dec 15, 2022
Unofficial iOS/macOS SDK for the Notion API.

NotionClient: a Notion SDK for iOS & macOS Unofficial Notion API SDK for iOS & macOS. This is an alpha version and still work in progress. TODO Featur

David De Bels 15 Aug 4, 2022
Unofficial Notion API SDK for iOS & macOS

NotionSwift Unofficial Notion SDK for iOS & macOS. This is still work in progress version, the module interface might change. API Documentation This l

Wojciech Chojnacki 59 Jan 8, 2023