Automate REST API Call?


#1

Hi I am new to the forums here and am working on a project for work.
My work has a twitter account that gets updated frequently.
On our website, I am trying to create a backend system that will grab the last 25 statuses posted on a nightly basis using the user_timeline (https://api.twitter.com/1.1/statuses/user_timeline.json). This worked on my first pull of the statuses. But now I am receiving an 135 error, “Could not authenticate you, Corresponds with a HTTP 401 - it means that your oauth_timestamp is either ahead or behind our acceptable range”. Is there a way to make the OAuth code valid for days, months, years? Or am I just doing something incorrectly? I am trying to automate this process as much as possible.

Thanks in advance for your help.
Brad


#2

You generate an OAuth access_token once but after that every single request to the Twitter API needs a new OAuth signature/timestamp/nonce/etc. Basically every OAuth request is only good once.


#3

Thanks for the quick response Abraham. The fact that you have to generate a new OAuth code every time you want to make a GET request seems very pointless and defeats many of the purposes of having this API. Maybe I am just not thinking clearly :smile: Is there another approach to accomplish what I am trying to do? Again I just want to be able to pull the last 25 statuses posted overnight. Or is there a way to dynamically create the OAuth signature/timestamp/nonce/etc?

Is there a different part of the API that can accomplish what I am trying to do?
This is just boggling my mind, it makes no sense that the OAuth request is only good once.

Thanks,
Brad


#4

There are a large number of libraries that create the OAuth signature dynamically. Most of them are easy to get started with.

E.g. using the TwitterOAuth PHP library it’s only a couple of lines.

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
$statuses = $connection->get("statuses/user_timeline", array("screen_name" => "twitter"));

#5

Great, thanks Abraham.
I will look into this.


#6

Actually, OAuth signatures are always timestamp-specific - this is baked in to the principles. You should use a library that does this work for you, to make things easier.