Giter Site home page Giter Site logo

instagramkit's Introduction

InstagramKit

CI Status Version Carthage compatible License Platform

An extensive Objective C wrapper for the Instagram API.

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.

####Installation

Getting started is easy. Just include the files from the directory 'InstagramKit' into your project and you'll be up and running. You may need to add AFNetworking to your project as well if you haven't already.

####Cocoapods Podfile

pod 'InstagramKit', '~> 3.0'

####Compatibility Earliest supported deployment target = iOS 6

####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.

Authentication

In order to make Authenticated calls to the API, you need an Access Token and often times a User ID. To get your Access Token, the user needs to authenticate your app to access his Instagram account.

To do so, redirect the user to https://instagram.com/oauth/authorize/?client_id=[Client ID]&redirect_uri=[Redirect URI]&response_type=token

Scope

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 IKLoginScope 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
// IKLoginScopeBasic is included by default.

IKLoginScope scope = IKLoginScopeRelationships | IKLoginScopeComments | IKLoginScopeLikes; 

NSURL *authURL = [[InstagramEngine sharedEngine] authorizarionURLForScope:scope];
[mWebView 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]. InstagramKit includes a helper method to validate this token.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSError *error;
    if ([[InstagramEngine sharedEngine] receivedValidAccessTokenWithURL:request.URL error:&error]) {
        if (!error) {
            //success!
            ...
        }
    }
    return YES;
}

####Usage

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 getSelfFeedWithSuccess:^(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. Read in detail about implementing Pagination for your requests effortlessly in the Pagination Wiki.

####Contributions?

Glad you asked. Check out the open Issues and jump right in. Please submit pull requests to the dev branch.

####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.

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

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

If you're using InstagramKit in your App or intend to, I'd be happy to hear from you.

~ @bhatthead

instagramkit's People

Contributors

shyambhat avatar ptwohig avatar ribeto avatar dezinezync avatar pchelnikov avatar adamjuhasz avatar adonoho avatar ytzong avatar nickthedude avatar miukal avatar mpieter avatar mkoosej avatar manumax avatar joshbeal avatar jacksonh avatar harrycheung avatar davebcn87 avatar almassapargali avatar krzd avatar

Watchers

James Cloos avatar open.thinhq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.