【发布时间】:2015-07-21 14:37:58
【问题描述】:
我看到了一些关于此的问题和答案,但不明白该怎么做。
我收到此错误:XMLHttpRequest cannot load https://accounts.google.com/o/oauth2/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 400.
正如我从之前的帖子中看到的,这是因为我无法向另一台服务器发出 HTTP POST 请求。我看到了一些关于使用 jsonp 的东西,但不明白如何..
这是我用来发送请求的函数:
var url = 'https://accounts.google.com/o/oauth2/token';
var payload = {
grant_type: 'authorization_code',
code: authResult['code'],
client_id: clientID,
client_secret: clientSecret,
redirect_uri: '',
dataType: 'jsonp'
};
$.post(url, {
form: payload
}, function(error, response, body) {
console.log(body);
});
【问题讨论】:
标签: javascript oauth oauth-2.0 google-api google-oauth