Git Product home page Git Product logo

instagramkit's Introduction

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.

instagramkit's People

Contributors

abury avatar adamjuhasz avatar adlai-holler avatar adonoho avatar afedor avatar alistra avatar dezinezync avatar gugges avatar joshbeal avatar manumax avatar mgarciam avatar mietzmithut avatar miukal avatar mkoosej avatar mpieter avatar natan avatar nickthedude avatar nicohinderling avatar pchelnikov avatar ptwohig avatar readmecritic avatar ribeto avatar ricsantos avatar samsonjs avatar shyambhat avatar stremsdoerfer avatar trauzti avatar urklc avatar ytzong avatar zzdjk6 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

instagramkit's Issues

AFNetworking 2.0

Hi,

Looks like a very interesting library and would love to give it a try. There is, however, one issue. In my project I use AFNetworking 2.0. In this library, AFNetworking 1.3 is used.

Would it be possible for you to make it compatible with AFNetworking 2.0?

Thanks for your time and work!

Problem while getting image from self feed

Hi shyambhat,

Thanks for sharing the nice your works.

I had problem while fetching images from self feed, please find below code.

"[[InstagramEngine sharedEngine] getSelfFeedWithCount:100 maxId:self.currentPaginationInfo.nextMaxId success:^(NSArray *media, InstagramPaginationInfo *paginationInfo)"

here, I assign feedcount to 100 but when I checked it "media" array then I had found only 33 records.

Please provide your feedback where I made mistake and please could you share how I add pagination in application.

Thanks in advanced.

Pod error

I get the following message when trying to install via cocoapods:

[!] Unable to satisfy the following requirements:

  • InstagramKit (= 2.1.0) required by Podfile

My podfile:
platform :ios, '7.0'

pod 'InstagramKit', '2.1.0'

Any idea what's causing the problem?

Media user bio doesn't work

The NSString media.user.bio always is an empty string although the user has a bio maybe the URL is incorrect?

Persist accessToken

It would be awesome if InstagramKit could persist the accessToken by itself, and handle if the token has been expired or revoked.

Likes don't seem to work

If I use likeMedia then getMedia and check the list of like usernames, it hasn't added it although the likeMedia method completes without error.

Follow method

Hi, I'm new at instagram SDK and was just wondering how to access the method to follow / unfollow a user? Is this method already declared in the demo project or do I have to do this by myself (and how :$)? :)

NSInvalidArgumentException with getSelfLikesWithSuccess call

When I call getSelfLikesWithSuccess I get an exception crash

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithString:]: nil argument

on line 19 of InstagramPaginationInfo.m

info[kNextMaxId] is in fact nil.

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

Custom Login Screen to avoid using a WebView

@shyambhat @dezinezync I was wondering if there was an effective way to have a custom login view to allow the user to login with their username and password instead of having a WebView presented to the user before login each time. Having one would be helpful to allow quicker access to the app and the ability to remember a user's username. I tried having a hidden WebView and then passing the username and password via javascript and end up getting an error after attempting the login. Have any of you found an effective way to do this?

Pagination ends after about a 100 images

When using pagination (both method #1 and #2 per your documentation) pagination information stops being returned by Instagram after about 100 images. Is it possible to page all the photos or is this a hard limit set by Instagram?

Parse Issue Expected a Type ERROR

Hi, I've just added InstagramKit to my project and I'm getting the following errors when trying to compile:

/Users/Neil/Documents/iOS Projects/Project1/Project1/InstagramKit/Engine/InstagramEngine.h:99:22: Expected a type

If i comment out the line i get another error:

/Users/Neil/Documents/iOS Projects/Project1/Project1/InstagramKit/Models/IKUserInPhoto.h:27:33: Unknown type name 'CGPoint'; did you mean 'Point'?

Im not sure what is causing this behaviour, I'm using Xcode 6.1, my app is for iOS 8 and up & I'm using Objective C.

Anyone have any ideas?

Allow Server Side authentication

Per Instagram's recommendations, it would be nice if this library provided a method to login with the code option instead of just always using token. The callback could expose this token, which the developer would then have to send to their server, and then eventually provide back to the InstagramKit engine.

Check out their guide for more information. It's not super vital, it would just be nice.

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.

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?

Swift compiler error. Expected a type

Just trying to use InstagramKit in a swift project with a bridging header.

Theres a Swift Compiler Error in InstagramEngine.h on line 84. "Expected a Type"

  • (bool)application:(UIApplication *)application
    openURL:(NSURL *)url
    sourceApplication:(NSString *)
    sourceApplication
    annotation:(id)annotation;

If I comment out that line, InstagramKit compiles and works.

Post requests for creating comments and likes

Similar to the

  • (void)getPath:(NSString_)path
    responseModel:(Class)modelClass
    parameters:(NSDictionary *)parameters
    success:(void (^)(id response))success
    failure:(void (^)(NSError_ error, NSInteger statusCode))failure

method.

Not Showing Correct Number of Images

I have this working in my app and it works great except that I'm trying to show more images but it is not showing the number I want. I have set the count but it is only showing the first 33 images.

[[InstagramEngine sharedEngine] getMediaForUser:@"196509072" count:50 maxId:self.currentPaginationInfo.nextMaxId withSuccess:^(NSArray *feed, InstagramPaginationInfo *paginationInfo)

Demo crashes

Thanks for this great project but I have nothing changed in the code and when I compile the app and run it it crashes after launching with an error:
" 'NSInternalInconsistencyException', reason: 'Invalid Instagram Client ID.' "

Does anybody else have this problem and can anybody please help me? :)

AFNetworking 2

Implemented on pr/5 branch. Testing for next milestone.

Requests may be cached?

If someone likes one of my photo's and I refresh my app by calling getMediaForUser the like count doesn't increase unless I background kill the app and try again, then the like count increases.

Could it be that GET requests are being cached?
Is there a way to specify not to cache requests?

Thanks

How do you check if a user's account is private or not?

Please bare with me, I know it has to do with the getRelationshipStatusOfUser method, but I don't necessarily understand how to implement it. I essentially just want to get whether the user is private or not and store that value in a standardUserDefault.

Relationships Pagination

Since most users have more than 50 followers/following, the calls to getUsersFollowedByUser, getFollowersOfUser, and getFollowRequests should make use of a pagination object.

Crash

nsurl - is nil

3 Foundation 0x017c7698 -[NSURL(NSURL) initWithString:relativeToURL:] + 89
4 Foundation 0x01829ba2 -[NSURL(NSURL) initWithString:] + 48
5 LikeMe 0x0009b0e8 -[InstagramPaginationInfo initWithInfo:] + 472
6 LikeMe 0x00072078 __68-[InstagramEngine getPath:parameters:responseModel:success:failure:]_block_invoke + 248

What should the redirect uri be?

Is there a specific app hook or address that we need to use? Something to let the app know it has been authenticated or denied?

I'm sure its a simple answer, I just can't figure it out...

Token validity

Hi, First of all I would like to thanks for such a good kit. I have one question how to check user token is valid, If token is not valid then again ask for login.

Note : Authenticated requests require an access_token. These tokens are unique to a user and should be stored securely. Access tokens may expire at any time in the future.

Regards
Alok

Crash "Assertion failure in -[InstagramEngine init]"

I'v just downloaded Instagram Kit to test it but it crashed in iOS 7 and iOS 8 Simulator.

  • Assertion failure in -[InstagramEngine init]
  • Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid Instagram Client ID.'

4 InstagramKit 0x000000010e356ded -[InstagramEngine init] + 2237
5 InstagramKit 0x000000010e356352 __31+[InstagramEngine sharedEngine]_block_invoke + 50

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

Redirecting to new view controller after authentication

Hi,
After login authentication you are displaying media data in the LoginviewController itself. But I need to redirect my user to separate viewcontroller(CustomController) and there I will place one button(logout) then user can be logged out there from there.
I hope you can understand my requirement.. I don't want to display LoginViewController after successful login. I need to display differentViewController there I will have logout button.can u help me ...please
I need not to display media data after successful login. user has to enter his credentials. after authorisation we display seperateViewController with welcome text..

The main thing is user has to be redirected to separate view controller(not loginviewcontroller)..sorry if I irritated with my query..

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.