Twitter API用户查找1000个用户

I'm trying to fetch 1000+ Twitter users from my database using this API call. However, Twitter lookup only allows 100 users per call, so how can I do it with 10 calls?

If I have 2232 users in my DB and I want to do a lookup on all users and get their details how to do it? Something which will count all the users being searched, break it into array of 100 elements, make the call for 100, and add the response back to database and then move onto the next 100.

I am using the tmhOAuth library for Twitter.

EDITED: I was able to accomplish it using this code , but my next question is how can i bind those values back to my account ? because the screen_name is a entry and not the KEY of the array, so how can i do it ?

    $accounts = $this->accounts->getAll();
    $accounts_chunk = array_chunk($accounts,100);
    foreach($accounts_chunk as $accounts){
        $screen_names = "";
        $last_key = end(array_keys($accounts));
        foreach($accounts as $k => $account){
            $screen_names .= $account->screen_name;
            if($last_key == $k){
                $screen_names .= "";
            } else {
                $screen_names .= ",";
            }          
        }
            $code = $this->twitter->request('GET', $this->twitter->url("1/users/lookup"),array('screen_name' => $screen_names));
            echo "<pre>";print_r(json_decode($this->twitter->response));echo "</pre>";
    }

But how to update values in DB using this .. i did a check but the sequence of the responses always changes so cannot use the current keys ..

You could loop through the max number of users and every hundredth time loop through hundred users and do your Twitter-magic there.

$iNumUsers = 2232; // or a mysql_num_rows-like result;

for($i = 0; $i < $iNumUsers; $i++) {

  if($i % 100 == 0) {

    for($j = $i; $j < 100; $j++) {

      // your twitter-code here
    }   
  }
}

Hi here are some simple steps to do this task

1: Get screen names from your db with limit of 100
2: impload with comma (join them with comma)
3: Send these 100 to users/lookup call and get data
4: (important) IF YOU RECEIVE AN ERROR OF "Rate limit exceeded" THEN USE PROXY
proxy will give you another chance to make next call of 100 users
5: decode json and send data to db (important) if you use user's id instead of screen name then it will be easy to update db

Still have problem shout a comment here

The Twitter API says

You are strongly encouraged to use a POST for larger requests.

So try posting your 2,000 IDs to them.

With regards to the second part of your question

the sequence of the responses always changes so cannot use the current keys ..

Start with your array of user IDd - $ids

Get the response from Twitter as $tl

// Place the users into an array
$sortedUsers = array();
foreach ($tl as $user) {
    $user_id = $user->id;
    // $tl is *unsorted* - but $ids is *sorted*. So we place the users from $tl into a new array based on how they're sorted in $ids
    $key = array_search($user_id, $ids);
    $sortedUsers[$key] = $user;
}

    // Sort the array by key so the most recent is at the top
ksort($sortedUsers);