API 1.1 GET/favorites/list.json Works For A Short Period Then Stops Working?


#1

Hi,

I hope somebody can help me and point me in the right direction in what I am doing wrong! Basically I am making a GET call for some favorited tweets and then storing them in a PHP variable which I can then use to write out a twitter feed based on this data.

I can get this working uing the code below. However. The problem I am having is that it only works for a short period then stops working. I think it is something to do with the time() perhaps? Am I doing somethnig wrong! Can it not ben done this way?

Thanks in advance!


$oauth_consumer_key = ‘-------------------’;
$oauth_consumer_key_secret = ‘-------------------’;
$oauth_token = ‘-------------------’;
$oauth_token_secret = ‘-------------------’;
$oauth_nonce = ‘-------------------’;
$oauth_signature = ‘-------------------’;
$oauth_timestamp = time();

$oauth_hash = ‘’;
$oauth_hash .= ‘oauth_consumer_key=XXXX&’;
$oauth_hash .= ‘oauth_nonce=’.$oauth_nonce.’&’;
$oauth_hash .= ‘oauth_signature_method=HMAC-SHA1&’;
$oauth_hash .= ‘oauth_timestamp=’.$oauth_timestamp.’&’;
$oauth_hash .= ‘oauth_token=559439614-XXXXXX&’;
$oauth_hash .= ‘oauth_version=1.0’;

$base = ‘’;
$base .= ‘GET’;
$base .= ‘&’;
$base .= rawurlencode(‘https://api.twitter.com/1.1/favorites/list.json’);
$base .= ‘&’;
$base .= rawurlencode($oauth_hash);

$key = ‘’;
$key .= rawurlencode(‘XXX’); // Consumer Secret
$key .= ‘&’;
$key .= rawurlencode(‘XXXXX’); // Access Token Secret

$signature = base64_encode(hash_hmac(‘sha1’, $base, $key, true));
$signature = rawurlencode($signature);

// Construct cURL Headers…

$oauth_header = ‘’;
$oauth_header .= ‘oauth_consumer_key="’.$oauth_consumer_key.’", ‘;
$oauth_header .= ‘oauth_nonce="’.$oauth_nonce.’", ‘;
$oauth_header .= ‘oauth_signature="’.$oauth_signature.’", ';
$oauth_header .= 'oauth_signature_method=“HMAC-SHA1”, ‘;
$oauth_header .= ‘oauth_timestamp="’.$oauth_timestamp.’", ‘;
$oauth_header .= ‘oauth_token="’.$oauth_token.’", ';
$oauth_header .= 'oauth_version=“1.0”, ';

$curl_header = array(“Authorization: Oauth {$oauth_header}”, ‘Expect:’);

// Make the cURL Request…

$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_URL, ‘https://api.twitter.com/1.1/favorites/list.json’);
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
$json = curl_exec($curl_request);
curl_close($curl_request);

$json = json_decode($json, true);


#2

You may want to reset your consumer key and secret – part of your paste had some details you don’t want to expose.

This method is rate limited at 15 requests per every 15 minutes. That might be why you’re requests stop working after awhile. Your OAuth code could use some cleanup as well. I recommend using an OAuth library with PHP like tmhOAuth or twitteroauth.


#3

Thanks for your reply and help. Can you recommend a better option then if this is limited?