2

I want to get an access_token according to this documentation 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.

4
  • Please indent your code with four spaces instead of adding HTML tags. 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) Commented Jun 16, 2011 at 17:39
  • Also, please define "does not work" - what behavior, exactly, are you seeing? 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? Commented Jun 16, 2011 at 17:49

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

attached URL is no more working, please Update with newer one
2

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.

Comments

0

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

3 Comments

It has not helped. Response says: Failed to validate oauth signature and token.
"b" and "c" are empty. "a" has parameter error="errror". that is all
In firebug at the Net tab I see the status of the request. It is "401 Unauthorized"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.