2013-01-15 45 views
0

請參閱下面的代碼。它的效果很好,我只需要在短時間內恢復我需要的,然後停止工作。我正在使用返回的數據創建Twitter Feed。這可不是這樣嗎?Twitter API 1.1 GET/favorites/list.json短時間工作然後停止工作?

$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=9bSWNyMCJ2Pu5VOibPU13A&'; 
$oauth_hash .= 'oauth_nonce='.$oauth_nonce.'&'; 
$oauth_hash .= 'oauth_signature_method=HMAC-SHA1&'; 
$oauth_hash .= 'oauth_timestamp='.$oauth_timestamp.'&'; 
$oauth_hash .= 'oauth_token=559439614-4cmIUCxb9FfUBsNTmeHZrox2FRpVQbvuED508lQm&'; 
$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('tF3CtuDtPGh8OYPBw7ZRs8Mrrj8kjmZRS0Q5jeA1vw'); // Consumer Secret 
$key .= '&'; 
$key .= rawurlencode('FDji1JuBeCNcQzjADjQdN3sOmk7xlAV3ILuooWCuYI'); // 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); 

回答