请参阅下面的代码。从根本上说它是有效的,我可以回收我所需要的东西,但仅限于短期,然后它就会停止工作。我正在使用返回的数据来创建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);
答案 0 :(得分:0)
是的 - 这是由于GET收藏夹/列表的Twitter速率限制,每个访问令牌每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/