-
Notifications
You must be signed in to change notification settings - Fork 266
Authentication
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.
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
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!
[self dismissViewControllerAnimated:YES
completion:nil];
}
}
return YES;
}