[英]Instagram authentication API not returning access token
The instagram "server side workflow" for authenticating a user and giving them a session access token doesn't work. 用于验证用户身份并为他们提供会话访问令牌的instagram“服务器端工作流”不起作用。 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
第一部分的工作方式是,我可以从此处获取代码: 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! 但是,当将此代码发布到https://api.instagram.com/oauth/access_token以获取访问令牌时,即使我已将其作为“身份验证”的一部分提供,它也仅会以“您必须提供客户端ID”作为响应。表单数据-我最初用于获取代码的相同客户ID!
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. 显然其他人已经报告了将数据发布为json的问题,然后通过使用“ application / x-www-form-urlencoded”解决了该问题-但这似乎现在也不起作用。
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"
grant_type应该为“ authorization_code”
convert the data object to json format , try 将数据对象转换为json格式,尝试
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",
},
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.