Reputation: 41
So I am trying to set up a simple authentication token web page to just get info from a test Instagram account. I have the following what I believe to be the token in the URL header, here is an example of what I get back:
code=a4eb4c7be00045969ff124fe5e840508
I want to pass this into a GET:
https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN
where the code I get goes where ACCESS-TOKEN is. Am I right in saying that this is the access token, or is it something else? If it is, how do I get this code into my get statement?
Upvotes: 0
Views: 126
Reputation: 663
That is not the access token. That is the code you need to swap for an access token. Look at the server side flow outlined here: https://instagram.com/developer/authentication/
Step 1: Direct user to this URL: https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code
Step 2: Get the redirect http://your-redirect-uri?code=CODE
This is where you get the code to swop for an access token.
Step 3: You will need to do a POST request to the access_token endpoint:
curl -F 'client_id=CLIENT_ID' \
-F 'client_secret=CLIENT_SECRET' \
-F 'grant_type=authorization_code' \
-F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \
-F 'code=CODE' \
https://api.instagram.com/oauth/access_token
You will then get a valid access token back that you can use in the GET:
https://api.instagram.com/v1/users/self/media/recent/?access_token=ACCESS-TOKEN
Upvotes: 1