如何使用Twitter Api在一个请求中获得超过20个列表成员?

时间:2010-03-11 05:07:43

标签: api twitter

我希望在一个请求中使用twitter api的用户超过20个 是否有任何参数指定它?

我正在使用这个api http://api.twitter.com/1/Barelyme/Politics/members.xml?cursor=-1

4 个答案:

答案 0 :(得分:2)

根据推特列表API文件:
http://apiwiki.twitter.com/Twitter-REST-API-Method:-GET-list-members

您只能在一次请求中获得超过20个。

答案 1 :(得分:2)

如果你正在使用twitteroauth by abraham,你可以遍历列表成员的页面(这个例子假设$ connection已经由twitteroauth的功能实现定义):

$user = $connection->get('account/verify_credentials'); //Gets/Tests credentials
$listmembers = $connection->get("{$user->screen_name}/LISTNAMEORID/members"); //Gets first page of list members; MUST edit "LISTNAMEORID"
$pagevalue = ""; //Set page value for later use

if($listmembers->next_cursor == 0){ //There is only one page of followers
    for ($j=0, $k=count($listmembers->users); $j<$k; $j++){
        //Your actions here
        //print_r($listmembers); //Displays the page of list members
    }
} else { //There are multiple pages of followers
    while ($pagevalue!=$listmembers->next_cursor){
        for ($j=0, $k=count($listmembers->users); $j<$k; $j++){
            //Your actions here
            //print_r($listmembers); //Displays the page of list members
        }
        $pagevalue = $listmembers->next_cursor; //Increment the 'Next Page' link
        $listmembers = $connection->get("{$user->screen_name}/LISTNAMEORID/members", array('cursor' => $pagevalue)); //Gets next page of list members; MUST edit "LISTNAMEORID"
    }
}

答案 2 :(得分:0)

可能不是,你可以多次轮询&gt; 1表示更多数据。

鉴于twitter说你做不到,你可能不能

答案 3 :(得分:0)

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$listmembers = $connection->get("MexicoTimes/mexicanpoliticians/members");
$members = array();
while ($listmembers->next_cursor_str != "0") {
    foreach($listmembers->users as $user)
        $members[] = $user;
    $cursor = $listmembers->next_cursor_str;
    $listmembers = $connection->get("MexicoTimes/mexicanpoliticians/members", array('cursor' => $cursor));
}

这个对我有用亚伯拉罕的Twitteroauth