Nodejs instagram api post requesting authcode and it gives err 400

I am trying to send a post request to instagram to get an access token but when I send it I get err 400 which means bad syntax. Am I using bad syntax?

const request = require('request');
var formData = {
client_id: "theclientid",
client_secret: "thelcientsecret",
grant_type: "authorization_code",
redirect_uri: "http://localhost:3000/",
code: "thecode"
}
request.post({
    uri: "https://api.instagram.com/oauth/access_token",
    formData: formData,
    json: true
}, function(err, res, body) {
    console.log(err);
    console.log(res.statusCode);
    if (!err && res.statusCode == 200) {
        var user = JSON.parse(body);
        console.log(user);
    }
});

1 answer

  • answered 2018-01-13 04:21 Nikola Andreev

    If you print the response body you will see what the problem is.

    { error_type: 'OAuthException',
      code: 400,
      error_message: 'Invalid Client ID' }
    

    Just try another client_id.