0

Trying to echo out all usernames via twitters public api. I get it to work if i skip the while loop. But i cant seems to get it to work with my loop.

 $url = 'https://api.twitter.com/1.1/followers/list.json';
$getfield = '?screen_name=zarazentio1&count=200';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$result = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();



   $results = json_decode($result,true);
   $getfield = $getfield.'&cursor='.$results["next_cursor"];
   echo $nextpage;
 ##  echo $results["users"]["2"]["screen_name"];

   foreach($results["users"] as $follow) {
   echo "</br>";
   echo $follow["screen_name"];



            }while ($results = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest());

While i do this it seems just to hang for a while then i get error from my host. If i remove this part (the last part).

while ($results = $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest());

The script works. I get names from the first page. And i have checked so i get a cursor for next page. But i think i am not understanding the WHILE loop function at all.

1 Answer 1

1

It seems like you are trying to combine both foreach and while, which is not possible in PHP. If you want to stop iterating after some condition is satisfied, simply use: if($condition) { break;}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.