Instagram is a popular social network and most IOS developers integrate Instagram API in their apps. In this post we will look at the steps of integrating and authenticating user’s (both signed authentication or unsigned authentication) with Instagram in IOS.
Click Register New Client, and register your app by filling necessary fields as mentioned below
1. Application Name 2. Description about application 3. Website 4. OAUTH redirect uri : Required if user denied access to your application then Instagram will redirect user to this uri filled by you in this field. You can enter same URL as entered in website field.
Next you have to select authentication options
1. Disable implicit OAuth : By enabling or checking this option you are telling that your app use Signed authentication that use server side OAUTH flow. If you want client side authentication that is unsigned calls then you can do it by unchecking the checkbox.
2. Enforce signed header: This option provide your app with better security as access token can be stolen and reused elsewhere.
To make a signed request you have to tick mark both checkboxes and if you want unsigned request then you can keep both of these checkboxes unchecked. Click register to create an application on Instagram.
Jump to code
Now at this point you have your client id and client secret with you.
Code in ViewController.h file
Open your viewController.h file and create IBOutlet for UIWebView, UIActivityIndicatorView, UILabel. We need property to differentiate weather we are going to use unsigned authentication or signed authentication.
In shouldStartLoadRequest method we will check for callBackUrl we get from Instagram. Below is the implementation code for callback url check. Here if we get our redirect url that we gave while creating client on Instagram in the callback url request then, we will fetch token in our handleAuth method(in case of unsigned call) or we will extract code from url and make a post request to Instagram server(in case of signed call)
NSLog(@”successfully logged in with Tocken == %@”,authToken);
If everything goes fine then you will get your authtoken. In handleAuth you can dismiss the controller so that it take you back to your application and store the token in userdefaults.
Now you can make request to Instagram server. If error persists then track back above steps.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.