L
L
LionG2019-03-07 15:03:46
Node.js
LionG, 2019-03-07 15:03:46

How to get instagram access_token using Server-side (Explicit) Flow?

I get a code. Next, the "code" needs to be sent as a POST request to instagram with additional arguments.

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

The result should be something like:
{
    "access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d",
    "user": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "..."
    }
}

I make a request via request.
var data = {
  client_id:config.ClientID,
  client_secret:config.ClientSecret,
  response_type:'token',
  redirect_uri:config.redirect_url,
  code:code
} 
request.post({url:'https://api.instagram.com/oauth/authorize', formData:data}, function (err, res, body) {...});

Returns 302 code, body is empty. Then I added it to request followAllRedirects:true(follow redirects), it began to return an html page with a bunch of styles, scripts and the insta logo in the center.
Confused me redirect_uri... why is it if I have to get json - mb they will send a response to this url ? Added a handler for this url... silence. Where to dig further?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
LionG, 2019-03-07
@LionG

response_type:'token',-> grant_type:'authorization_code',
and url https://api.instagram.com/oauth/access_token, let's go json...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question