如何通过一个请求获得所有关注者?如果我这样做,$this->twitter->getFollowers();
我就会得到100个粉丝;
这是获取粉丝的代码
/**
* Returns the authenticating user's followers.
*
* @return array
* @param string[optional] $id The id or screen name of the user for whom to request a list of followers.
* @param int[optional] $page
*/
public function getFollowers($id = null, $page = null)
{
// build parameters
$aParameters = array();
if($page !== null) $aParameters['page'] = (int) $page;
// build url
$url = 'statuses/followers.xml';
if($id !== null) $url = 'statuses/followers/'. urlencode($id) .'.xml';
// do the call
$response = $this->doCall($url, $aParameters, true, false);
// convert into xml-object
$xml = @simplexml_load_string($response);
// validate
if($xml == false) throw new TwitterException('invalid body');
// init var
$aUsers = array();
// loop statuses
foreach ($xml->user as $user) $aUsers[] = $this->userXMLToArray($user);
// return
return (array) $aUsers;
}
Run Code Online (Sandbox Code Playgroud)
当你打电话给$this->twitter->getFollowers();
你基本上每页限制100个粉丝.如果您碰巧有超过100个,请尝试利用分页随后访问所有关注者...
另见:http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-statuses%C2%A0followers
光标.可选的.将结果分解为页面.单个页面包含100个用户.建议用户跟随许多其他用户.提供值-1以开始分页.提供在响应主体的next_cursor和previous_cursor属性中返回的值,以便在列表中来回切换.
示例:http://twitter.com/statuses/followers/barackobama.xml?cursor = -1
示例:http://twitter.com/statuses/followers/barackobama.xml?cursor = 1300794057949944903