如何使用 Twitter Api 在单个请求中获取 20 多个列表成员? [英] How to use Twitter Api To Get more than 20 list Members in a single request?

查看:15
本文介绍了如何使用 Twitter Api 在单个请求中获取 20 多个列表成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个请求中让超过 20 个用户使用 twitter api有什么参数可以指定吗?

i want to get more than 20 users using the the twitter api in a single request is there any parameter that specifies it?

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

i am using this api http://api.twitter.com/1/Barelyme/Politics/members.xml?cursor=-1

推荐答案

如果您使用的是 twitteroauth by abraham,您可以遍历列表成员的页面(此示例假设 $connection 已由 twitteroauth 的功能实现定义):

If you're using twitteroauth by abraham, you can iterate through the pages of list members (this example assumes $connection is already defined by a functional implementation of 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"
    }
}

这篇关于如何使用 Twitter Api 在单个请求中获取 20 多个列表成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆