【发布时间】:2011-09-30 10:48:27
【问题描述】:
我正在尝试使用 jQuery 为 Google API 的 OAuth 的纯客户端实现。 我正在使用oauth.js 和sha1.js 库。
url = "https://www.google.com/accounts/OAuthGetRequestToken";
var accessor = { consumerSecret: 'abc' };
var parameter = {
oauth_consumer_key:'www.oauthorization.appspot.com',
oauth_signature_method:'HMAC-SHA1',
scope:'http://www.google.com/calendar/feeds/private/default/full',
oauth_timestamp:010111,oauth_nonce:abc,
oauth_signature:qbc,
oauth_callback:'http://abc.appspot.com/'
}
OAuth.setTimestampAndNonce(message);
OAuth.SignatureMethod.sign(message, accessor);
$.ajax({
url: url,
type: "POST",
beforeSend: function( xhr ) {
xhr.overrideMimeType( 'application/x-www-form-urlencoded' );
xhr.setRequestHeader('Authorization', 'OAuth');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
},
data: parameter
});
在触发上述 AJAX 调用时,我在 firefox 上收到 405 method not allowed 错误,并且 Access-Control-Allow-Origin 不允许使用 Origin null。 在 chrome 中.
请帮助解决这些错误或向我指出一些适用于 Google 的 jQuery OAuth 实现的工作示例。
【问题讨论】:
-
JSONP 在 POST 中不起作用。在这里阅读更多:stackoverflow.com/questions/3860111/…
-
你成功了吗?我在尝试使用 OAuth 时碰壁了。
标签: jquery oauth google-api