Tags:#Instagramintegration #IOS #Tutorial #login via instagram
Introduction to Instagram integration in iOS
Instagram is the popular app that allows user to share pictures and small videos with their followers and people around the world. In iOS app, developers can utilize Instagram Api in two ways
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.
Open .xib, drag all controls declared in viewController.h file and connect outlets with them. Set UIWebView delegates as we need to implement delegates.
Code in ViewController.m file
TypeOfAuthentication is to be set when you are navigating to viewController or you can set it in viewDidLoad method as
self.typeOfAuthentication = @”UNSIGNED”
Open your viewController.m file and in its viewDidAppear method load your loginWebView with authorization url,
Beloware the UIWebView delegate methods that we need to implement.
shouldStartLoadRequest : This is needed as we need to cross check our authentication with Instagram and here we get our access Token (in case of unsigned call ) and code (in case of signed call)
webViewDidStartLoad: To show activity indicator animated
webViewFinishLoad: To hide activity indicator.
failWithError: In case we are not able to load webView then stop activity indicator.
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.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
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.