Android: Authenticate with Instagram and pull profile data
|I was searching for SDK to integrate Instagram into one of my apps, could not find any offical SDK. This is kind of bummer to me, considering the popularity of Instagram, I expected SDK for integration. After seeing their REST API I understood why SDK is not required. The API is very simple to use, I could every thing done in a single afternoon.
My target was to get user authenticated with Instagram and pull profile pic. I will explain how do the same in the following section.
It is possible to extract Instagram user data in an android application with user’s permission.
The Instagram API Platform can be used to build non-automated, authentic, high-quality apps and services that:
- Help individuals share their own content with 3rd party apps.
- Help brands and advertisers understand, manage their audience and media rights.
- Help broadcasters and publishers discover content, get digital rights to media, and share media with proper attribution.
Basic steps to use Instagram API are
- Register your application
- Authenticate
- Start making request
To start with , you need to have a Instagram account.
Steps to get user data using Instagram API
- Register your android application here https://www.instagram.com/developer/register/. Enter redirect url, app name etc. Once the application is registered, OAuth client_id and client_secret is assigned for your applications.
- Until your app is published, you can only use sandbox. You can send invites to the users who you wish test the app. Goto Manage Client option >> Sandbox tab to add users by entering users Instagram user id. User should accept this request from their account from Sandbox invites tab in https://www.instagram.com/developer/ .
- In the android application, open a web view with request URL ( Request URL = Client ID + Redirect URL)
- The above steps gives you an Access Token
- Hit the below URL to get user information
https://api.instagram.com/v1/users/self/?access_token=<[access token from above step]>
You can also get users recent feed, for more info on available endpoints, checkout REST API.