我正在使用Twitter API为我的推文检索转发器。代码涉及2个For-Next循环,理论上可行。我的问题是以下代码容易受到“超出请求限制”的问题,并且在第3次尝试运行脚本时,我遇到了上述限制错误。
我可以问你的建议/评论,因为我可能只是做错了吗?代码如下:
<?php
$urlUserTimeLine = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$getfield = '?count=200&screen_name=' . $AuthenticatedScreenName . '&since_id=' . $TweetID;
$requestMethod = 'GET';
$UserTimeLineResponse = $twitter->setGetfield($getfield)
->buildOauth($urlUserTimeLine, $requestMethod)
->performRequest();
$UserTimeLineResponseJSONDecoded = json_decode($UserTimeLineResponse, true);
foreach ($UserTimeLineResponseJSONDecoded as $key_post_to_url => $jsons_post_to_url) {
foreach ($jsons_post_to_url as $key_post_to_url2 => $jsons_post_to_url2) {
if($key_post_to_url2=="id"){
$TweetID2 = $jsons_post_to_url2;
$urlReTweets = 'https://api.twitter.com/1.1/statuses/retweets/' . $TweetID2 . '.json';
$ReTweeterResponse = $twitter->setGetfield($getfieldReTweets)
->buildOauth($urlReTweets, $requestMethodReTweets)
->performRequest();
$ReTweeterResponseJSONDecoded = json_decode($ReTweeterResponse, true);
foreach ($ReTweeterResponseJSONDecoded as $key_post_to_url => $jsons_post_to_url) {
foreach ($jsons_post_to_url['user'] as $key_post_to_url2 => $jsons_post_to_url2) {
if($key_post_to_url2=="screen_name"){
echo $jsons_post_to_url2;
}
}
}
}
}
}
?>