View Single Post
Old 01-17-2013, 01:57 PM   PM User | #1
cloudstryphe
New Coder

 
Join Date: Mar 2012
Posts: 62
Thanks: 7
Thanked 0 Times in 0 Posts
cloudstryphe is an unknown quantity at this point
PHP looping with step of 100

Hello everyone. I'm trying to get all the information from the people my user follows on twitter. The problem is with twitter you have to make 2 separate calls to get all the information:

Call 1 returns all the ID's of the users my user follows.

Call 2 returns the user information of up to 100 users which can be asked via a comma separated argument.

So basically I have to get all the user ids from first call and then run 100 at a time through call 2 and put them in another array for storage.

I've been digging at this for a while and haven't been able to come up with a solution. I figured array_splicing might be the way to go but I haven't been able to increment it correctly. This is what I've been able to do so far...

Code:
		$users_array = array();

		$i = 0;

		$tw_user_array = $twitteroauth->get('friends/ids');

			if($i == 0) {
				$begin = 0;
				$end = 100;
			}

			else {

				$begin = $i * 100;
				$end = $i * 100 + 100;

			};
			$user_array = array_splice($tw_user_array->ids, $begin, $end);

			while (count($user_array) < 101) {

				array_push($users_array, $user_array);

				$i++;

			};


		$cs = implode(",", $users_array);

		$parameters = array('user_id' => "$cs");

		$user_objects = $twitteroauth->get('users/lookup', $parameters);

		return $user_objects;
All help is greatly appreciated.
cloudstryphe is offline   Reply With Quote