我正在使用 Twitter API 来检索我的推文的转发者。该代码涉及 2 个 For-Next 循环,理论上可行。我的问题是以下代码容易受到“超出请求限制”问题的影响,并且在第三次尝试运行脚本时,我遇到了上述限制错误。
我可以征求您的建议/意见吗,因为我可能做错了?代码如下:
<?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;
}
}
}
}
}
}
?>