我真的不知道如何在 Twitter 的 API 中使用Curesor参数,例如 -这里。我应该为每 100 个关注者进行一次新的 API 调用吗?
如果有人可以提供一个 PHP 示例来获取完整的追随者列表,我会很高兴,假设我有 100 多个...
提前致谢!
您需要将光标值传回 API 以获取下一个“块”关注者。然后从该块中获取游标参数并将其传回以获取下一个块。它就像一个“获取下一页”机制。
查看http://code.google.com/p/twitter-boot/source/browse/trunk/twitter-bot.php
foreach ($this->twitter->getFollowers(,0 ) as $follower)//the 0 is the page
{
if ($this->twitter->existsFriendship($this->user, $follower['screen_name'])) //If You Follow this user
continue; //no need to follow now;
try
{
$this->twitter->createFriendship($follower['screen_name'], true); // If you dont Follow Followit now
$this->logger->debug('Following new follower: '.$follower['screen_name']);
}
catch (Exception $e)
{
$this->logger->debug("Skipping:".$follower['screen_name']." ".$e->getMessage());
}
}
}
自从提出这个问题以来,Twitter API 在许多方面发生了变化。
游标用于对具有许多结果的 API 响应进行分页。例如,获取关注者的单个 API 调用将检索最多 5000 个 id。
如果你想获得一个用户的所有关注者,你将不得不进行一个新的 API 调用,但这一次你必须指出你第一个响应中的“next_cursor”数字。
如果有用,以下 python 代码将从给定用户检索关注者。
它将检索由常量指示的最大页数。
注意不要被封号(即:匿名调用的api调用/小时不要超过150次)
import requests
import json
import sys
screen_name = sys.argv[1]
max_pages = 5
next_cursor = -1
followers_ids = []
for i in range(0,max_pages):
url = 'https://api.twitter.com/1/followers/ids.json?screen_name=%s&cursor=%s' % (screen_name, next_cursor)
content = requests.get(url).content
data = json.loads(content)
next_cursor = data['next_cursor']
followers_ids.extend(data['ids'])
print "%s have %s followers!" % (screen_name, str(len(followers_ids)))