【发布时间】:2014-05-04 21:29:00
【问题描述】:
我正在关注this guide 并尝试从 google api 获取访问令牌。我已经得到了一个授权码。所以我使用 angularjs 将 httprequest 发送到谷歌服务器。问题是我总是得到错误的请求答案。这是我的代码:
$http({
method: 'POST',
url: 'https://accounts.google.com/o/oauth2/token',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
params : {
code : '4/heMv6ozWwCxS5RyTzCgThAgxvRyk.oske-bNEGOUTOl05ti8ZT3YnwwH8iQI',
client_id : GoogleAppInfo.clientId,
redirect_uri : GoogleAppInfo.redirect_uri,
client_secret : GoogleAppInfo.client_secret,
grant_type : 'authorization_code'
},
data :'Demo' //just data to apply the heaser
}).
success(function(data, status, headers, config) {
alert('secsses');
}).
error(function(data, status, headers, config) {
alert('error');
});
我使用PostMan chorme addon 来测试我的参数,它正在使用邮递员。 那里的错误是因为此请求的身份验证码已过期,但它可以正常工作!
有人对这个问题有意见吗? 非常感谢!!
【问题讨论】:
-
我使用服务器代码来获取我的令牌。我不认为你想把你的秘密放在客户端设备上。
标签: angularjs google-api access-token