1

I am trying to use jquery to do a get request and download tweets from twitter, except I don't understand how to authenticate the request. I have a twitter account and registered an app, so I can see all its token values. I don't understand how to actually use those values to make a request.

I have this so far:

$(function() {
    var token = "<my token>";
    $.ajax({
        dataType: "json",
        url: "https://api.twitter.com/1.1/favorites/list.json?count=2&screen_name=episod",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Authorization", token);
        },
        success: function() {alert(2);},
        fail: function() {console.log( "error" );}
    });
});

But where do I use the token values?

Can anyone help please?

Thanks

omega
  • 40,311
  • 81
  • 251
  • 474

1 Answers1

0

You need to add an Authorization: header to the GET request. See this answer.

Community
  • 1
  • 1
Christian Ternus
  • 8,406
  • 24
  • 39
  • I changed the code above. Now I get the error message "405 Method Not Allowed". Do you know whats wrong? – omega Sep 20 '13 at 19:01
  • Are you setting the auth token properly, as in https://dev.twitter.com/docs/auth/authorizing-request? Does it work for another API URL? Does it work if you set the method to GET explicitly? – Christian Ternus Sep 21 '13 at 20:52