请看我下面的代码。基本上,它起作用了,我找回了我需要的东西,但只在短期内,然后它就停止工作了。我想使用返回的数据来创建一个Twitter提要。难道这不是这样的吗?
$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);发布于 2013-07-30 03:28:10
是的-这是由于推特对GET favorites/list的速率限制,允许15个请求,每个15分钟窗口,每个访问令牌:https://dev.twitter.com/docs/rate-limiting/1.1/limits
为了克服这个问题,您可能需要在PHP中使用缓存解决方案将输出写入本地文件,并使用cron作业请求PHP。此链接应该会对您有所帮助:http://www.webdevdoor.com/php/jquery-twitter-feed-part2-caching-tweets/
https://stackoverflow.com/questions/14348772
复制相似问题