1

I'm trying to get the latest tweets from a particular user using PHP and CURL and the new 1.1 API, I created my new App in the twitter website and went to the OAuth tool tab to generate the signature and according to the page it generates the following curl command:

curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=2&screen_name=twitter' --header 'Authorization: OAuth oauth_consumer_key="Waqd223QDuge6l9UboBldg", oauth_nonce="8a9beae863838b0ba2bc6ac03bc9757e", oauth_signature="u2PrZ5g14HGb39pHoYl9azHp6vg%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1355408402", oauth_token="171967067-lyLujNed9QyVBfmlfAkFXiUt5KIQkqrCMwg6utFc", oauth_version="1.0"'

Which works fine in my terminal, however when I try to replicate it in PHP I get a "Could not authenticate you" error, this is what I have so far:

$options = array(
    URLOPT_HTTPHEADER      => array('Authorization: OAuth oauth_consumer_key="Waqd223QDuge6l9UboBldg", oauth_nonce="8a9beae863838b0ba2bc6ac03bc9757e", oauth_signature="toLnir5cHUUvEj8X29SdzjlOTXc%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="' . time() . '", oauth_token="171967067-lyLujNed9QyVBfmlfAkFXiUt5KIQkqrCMwg6utFc", oauth_version="1.0"'),
    CURLOPT_HEADER         => false,
    CURLOPT_URL            => 'https://api.twitter.com/1.1/statuses/user_timeline.json?count=2&screen_name=twitter',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => false
);

$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);

$twitter_data = json_decode($json);

var_dump($twitter_data);

The only thing I'm changing is the oauth_timestamp where I use the time() function to get the current time, I figure I must be passing the wrong options to the curl function but I can't figure it out.

Thanks in advance.

Javier Villanueva
  • 3,886
  • 13
  • 48
  • 80
  • I'm thinking it has something to do with the `oauth_signature` since the `oauth_timestamp` is different then the signature should be different as well? – Javier Villanueva Dec 13 '12 at 15:13

3 Answers3

3

Here you can find an example of getting tweets with the twitter api 1.1 and curl

Simplest PHP example for retrieving user_timeline with Twitter API version 1.1

Community
  • 1
  • 1
lackovic10
  • 994
  • 1
  • 8
  • 11
  • Thanks that's what I ended up using, turns out the `oauth_signature` has to be remade with every request since the timestamp changes as well – Javier Villanueva Dec 24 '12 at 16:03
0

Took me a while to get something working but I finally did and have pushed a standalone class and demo to GitHub that should be pretty easy to follow.

https://github.com/skaterdav85/twitter-library

Animal Rights
  • 9,107
  • 6
  • 28
  • 40
0

Really simple php wrapper for Twitter 1.1 rest api

https://github.com/vojant/Twitter-php