angular 和 dropbox 无法通过代码流获取令牌
angular and dropbox can(t get token with code flow
我有这个片段:
var req = {
method: 'POST',
url: 'https://api.dropboxapi.com/oauth2/token',
headers: {'Content-Type': 'application/json'},
data: {
'code': authCode,
'grant_type': 'authorization_code',
'client_id': 'my_id',
'client_secret': 'my_secret',
'redirect_uri':'http://localhost%3A8080/main'
}
};
return $http(req).then(function(response){
console.log(response.status);
return response;
}, function(err){
console.log(err);
});
罐子总是以 "bad request" 结束,因为“"No auth function available for given request"”
相同的数据与发送 REST 请求的工具一起使用...所以我不知道我在这里遗漏了什么...
可以帮忙吗?
错误消息表明 API 没有收到预期的参数,或者至少没有收到预期的格式。 documentation for /1/oauth2/token 说:
Calls to /oauth2/token need to be authenticated using the apps's key and secret. These can either be passed as POST parameters (see parameters below) or via HTTP basic authentication. If basic authentication is used, the app key should be provided as the username, and the app secret should be provided as the password.
不过,根据您的 Content-Type
header,您似乎试图提供 JSON 的参数。尝试将它们作为 POST 参数发送。
我有这个片段:
var req = {
method: 'POST',
url: 'https://api.dropboxapi.com/oauth2/token',
headers: {'Content-Type': 'application/json'},
data: {
'code': authCode,
'grant_type': 'authorization_code',
'client_id': 'my_id',
'client_secret': 'my_secret',
'redirect_uri':'http://localhost%3A8080/main'
}
};
return $http(req).then(function(response){
console.log(response.status);
return response;
}, function(err){
console.log(err);
});
罐子总是以 "bad request" 结束,因为“"No auth function available for given request"”
相同的数据与发送 REST 请求的工具一起使用...所以我不知道我在这里遗漏了什么...
可以帮忙吗?
错误消息表明 API 没有收到预期的参数,或者至少没有收到预期的格式。 documentation for /1/oauth2/token 说:
Calls to /oauth2/token need to be authenticated using the apps's key and secret. These can either be passed as POST parameters (see parameters below) or via HTTP basic authentication. If basic authentication is used, the app key should be provided as the username, and the app secret should be provided as the password.
不过,根据您的 Content-Type
header,您似乎试图提供 JSON 的参数。尝试将它们作为 POST 参数发送。