2
我正在瀏覽this guide並試圖從google api獲取accses令牌。我艾倫得到了一個認證代碼。所以我使用angularjs發送httprequest到谷歌服務器。問題是我總是得到不好的請求答案。這是我的代碼:無法使用angularjs從谷歌獲取訪問令牌
$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來測試我的參數,可以和它的工作的郵遞員。 那裏的錯誤是因爲這個請求的授權碼已過期,但它正在工作!
有沒有人對這個問題有好感? 非常感謝!
我使用服務器代碼來獲取我的令牌。我不認爲你想把你的祕密放在客戶端設備上。 –