【发布时间】:2018-07-23 17:37:54
【问题描述】:
我正在尝试从以下 URL 接收访问令牌:
https://api.bufferapp.com/1/oauth2/token.json
以下代码是我的 POST 请求,我似乎根据 Buffer API 文档和 OAuth 2 规则包含了所有内容:
$.ajax({
type: 'POST',
url: 'https://api.bufferapp.com/1/oauth2/token.json',
headers: {
'Accept': 'application/json',
'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8",
},
data: {
client_id: "{MY_CLIENT_ID}",
client_secret: "{MY_CLIENT_SECRET}",
redirect_uri: "http://localhost/testexample",
code: "{MY_AUTH_CODE}",
grant_type: "authorization_code"
},
success: function(response) {
console.log(response);
},
error: function(response) {
console.log(response);
},
dataType: "jsonp"
});
当我执行代码时,我收到错误: net::ERR_ABORTED,并且 URL 返回: {"error":"invalid_request","error_description":"无效的 grant_type 参数或缺少参数"}
我做错了什么?
感谢您的宝贵时间。
【问题讨论】:
标签: jquery json ajax api oauth-2.0