Twitter authentication with Javascript
I want to get an access_token according to this docu开发者_StackOverflowmentation http://dev.twitter.com/doc/post/oauth/request_token. I use 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.
Check user login & signup provided by Twitter's @Anywhere JavaScript library. https://dev.twitter.com/docs/anywhere/welcome#login-signup
That may be exactly what you want, much easier to use than the raw OAuth.
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 library to generate oauth_signature.
You're probably calling this script outside the api.twitter.com
domain. Try with dataType: "jsonp"
.
精彩评论