admin管理员组

文章数量:1293746

I want to get an access_token according to this documentation . I use javascript.

$.ajax({
    url: "",
    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.

I want to get an access_token according to this documentation http://dev.twitter./doc/post/oauth/request_token. I use javascript.

$.ajax({
    url: "http://api.twitter./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.

Share edited Jun 16, 2011 at 17:42 Alexander asked Jun 16, 2011 at 17:36 AlexanderAlexander 6073 gold badges11 silver badges23 bronze badges 4
  • Please indent your code with four spaces instead of adding HTML tags. – SLaks Commented Jun 16, 2011 at 17:38
  • Hi Alexander. You can use 4 spaces (or the {} button in the question entry form) to format your code to be more readable, as I have done so above. Also, html br elements are not necessary (and are in fact ignored) – Matt Commented Jun 16, 2011 at 17:39
  • Also, please define "does not work" - what behavior, exactly, are you seeing? – Matt Commented Jun 16, 2011 at 17:41
  • Maybe a stupid suggestion, but just to be sure; Are you sure you have included jQuery in your HTML as well? – fijter Commented Jun 16, 2011 at 17:49
Add a ment  | 

3 Answers 3

Reset to default 3

Check user login & signup provided by Twitter's @Anywhere JavaScript library. https://dev.twitter./docs/anywhere/wele#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.. You will likely want to use a JavaScript library to generate oauth_signature.

You're probably calling this script outside the api.twitter. domain. Try with dataType: "jsonp".

本文标签: Twitter authentication with JavascriptStack Overflow