使用 Javascript 进行 Twitter 身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6376144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Twitter authentication with Javascript
提问by Alexander
I want to get an access_token according to this documentation http://dev.twitter.com/doc/post/oauth/request_token. I use javascript.
我想根据这个文档http://dev.twitter.com/doc/post/oauth/request_token获得一个 access_token 。我使用javascript。
$.ajax({
url: "http://api.twitter.com/oauth/request_token",
type: "POST",
contentType: "json",
data: {
oauth_consumer_key: "DFwQqCnOTaYVbZQdBFqpR",
oauth_signature_method: "HMAC-SHA1",
oauth_timestamp: parseInt((new Date()).getTime() / 1000),
oauth_nonce: "R" + parseInt((new Date()).getTime() / 1000),
oauth_version: "1.0"
},
success: function (data) {
debugger;
},
error: function (a, b, c) {
debugger;
}
});
But it does not work at all. Always return error, never success.
但它根本不起作用。总是返回错误,永远不会成功。
回答by Ivan Krechetov
Check user login & signup provided by Twitter's @Anywhere JavaScript library. https://dev.twitter.com/docs/anywhere/welcome#login-signup
检查 Twitter 的 @Anywhere JavaScript 库提供的用户登录和注册。https://dev.twitter.com/docs/anywhere/welcome#login-signup
That may be exactly what you want, much easier to use than the raw OAuth.
这可能正是您想要的,比原始 OAuth 更容易使用。
回答by abraham
You are not signing your request. You can read a more in depth direction on how to sign an OAuth reqeust on dev.twitter.com. You will likely want to use a JavaScript libraryto generate oauth_signature.
您没有签署您的请求。您可以在 dev.twitter.com 上阅读有关如何签署 OAuth 请求的更深入的指导。您可能希望使用JavaScript 库来生成 oauth_signature。
回答by pawlik
You're probably calling this script outside the api.twitter.com
domain. Try with dataType: "jsonp"
.
您可能在api.twitter.com
域外调用此脚本。尝试使用dataType: "jsonp"
.