Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an Instagram Access Token

I'm really struggling in how I'm meant to get my access token for Instagram,

I've registered a new client and then I used this URL

https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

to fill in the clients ID and redirect Url.

I then was redirected to a page where it displayed a code in the Url but from there I don't have a clue where id then get my access token.

like image 832
Gerry Mckay Avatar asked May 11 '13 11:05

Gerry Mckay


People also ask

Does Instagram have a token?

Authenticated requests need Instagram Access token. Access Token is an opaque string that identifies a user, app, or page. It can be used by the app to make graph API calls and is unique to each user. Instagram Access Token is essential for the usage of most Instagram based apps.

How do I get access token?

To get the Client Access Token for an app, do the following: Sign into your developer account. On the Apps page, select an app to open the dashboard for that app. On the Dashboard, navigate to Settings > Advanced > Security > Client token.

How do you get the Instagram access token in smash balloons?

1) Navigate to the Instagram Feed Settings page in your WordPress admin and click on the blue Instagram login button: 2) If you're not logged into your Instagram account then you will be prompted to do so in order to authorize the plugin to obtain a token.

How do you get a long live access token on Instagram?

Get a Long-Lived Token Your request must be made server-side and include: A valid (unexpired) short-lived Instagram User Access Token. Your Instagram App Secret (App Dashboard > Products > Instagram > Basic Display > Instagram App Secret)


2 Answers

Link to oficial API documentation is http://instagram.com/developer/authentication/

Longstory short - two steps:

Get CODE

Open https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code with information from http://instagram.com/developer/clients/manage/

Get access token

curl \-F 'client_id=CLIENT-ID' \     -F 'client_secret=CLIENT-SECRET' \     -F 'grant_type=authorization_code' \     -F 'redirect_uri=YOUR-REDIRECT-URI' \     -F 'code=CODE' \     https://api.instagram.com/oauth/access_token 
like image 183
Marek Jalovec Avatar answered Oct 19 '22 09:10

Marek Jalovec


Almost all of the replies that people have posted so far only cover how to handle access tokens on the front end, following Instagram's client-side "implicit authentication" procedure. This method is less secure and unrecommended according to Instagram's API docs.

Assuming you are using a server, the Instagram docs sort of fail in providing a clear answer about exchanging a code for a token, as they only give an example of a cURL request. Essentially you have to make a POST request to their server with the provided code and all of your app's information, and they will return a user object including user information and the token.

I don't know what language you are writing in, but I solved this in Node.js with the request npm module which you can find here.

I parsed through the url and used this information to send the post request

var code = req.url.split('code=')[1];  request.post(   { form: { client_id: configAuth.instagramAuth.clientID,             client_secret: configAuth.instagramAuth.clientSecret,             grant_type: 'authorization_code',             redirect_uri: configAuth.instagramAuth.callbackURL,             code: code           },     url: 'https://api.instagram.com/oauth/access_token'   },   function (err, response, body) {     if (err) {       console.log("error in Post", err)     }else{       console.log(JSON.parse(body))     }   } ); 

Of course replace the configAuth stuff with your own information. You probably aren't using Node.js, but hopefully this solution will help you translate your own solution into whatever language you are using it in.

like image 34
Quest Avatar answered Oct 19 '22 11:10

Quest