Instagram身份验证API不返回访问令牌

时间:2017-04-25 15:05:06

标签: javascript angularjs authentication oauth instagram

用于验证用户身份并为其提供会话访问令牌的instagram“服务器端工作流程”不起作用。第一部分的作用是我可以从这里得到一个代码: https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

但是,将此代码发布到 https://api.instagram.com/oauth/access_token 为了获得访问令牌,它只是响应“你必须提供一个客户端ID”,即使我已经提供了这个作为表单数据的一部分 - 我用来获取代码的客户端ID相同! / p>

以下是我正在使用的代码:

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",
                },
            })

        }

显然其他人报告了将数据发布为json的问题,然后使用“application / x-www-form-urlencoded”解决了这个问题 - 但是现在这似乎都没有用。

以下是返回的确切错误消息:

{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 个答案:

答案 0 :(得分:2)

grant_type应为' authorization_code'

答案 1 :(得分:1)

将数据对象转换为json格式,尝试

 data: JSON.stringify(data),

您的代码将如下所示

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",
                },
            })

        }
相关问题