2
votes

The instagram "server side workflow" for authenticating a user and giving them a session access token doesn't work. First part works in that I can get a code back from here: https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

However, when posting this code to https://api.instagram.com/oauth/access_token in order to obtain the access token, it just response with "YOU MUST PROVIDE A CLIENT ID", even though I have provided this as part of the form data - the same client id I used to get the code in the first place!

Here is the code I am using:

getIgToken: function (igCode) {
            let data = {
                client_id: config.imported.instagram.client_id,
                client_secret: config.imported.instagram.client_secret,
                grant_type: 'authorization_code',
                redirect_uri: 'http://localhost:5000/app/scrape',
                code: igCode
            }
            return $http({
                method: 'POST',
                url: 'https://api.instagram.com/oauth/access_token',
                data: data,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
            })

        }

Apparently others have reported problems with posting the data as json, which have then been resolved by using "application/x-www-form-urlencoded" - however this doesn't seem to work either now.

Here is the exact error message returned:

{error_type: "OAuthException", code: 400, error_message: "You must provide a 
client_id"}
code:400
error_message:"You must provide a client_id"
error_type:"OAuthException"
2

2 Answers

2
votes

grant_type should be 'authorization_code'

1
votes

convert the data object to json format , try

 data: JSON.stringify(data),

your code will look like this

getIgToken: function (igCode) {
            let data = {
                client_id: config.imported.instagram.client_id,
                client_secret: config.imported.instagram.client_secret,
                grant_type: 'authorisation_code',
                redirect_uri: 'http://localhost:5000/app/scrape',
                code: igCode
            }
var jsonData= JSON.stringify(data)
            return $http({
                method: 'POST',
                url: 'https://api.instagram.com/oauth/access_token',
                data: jsonData,
                headers: {
                    "Content-Type": "application/x-www-form-urlencoded",
                },
            })

        }