2

我真的不知道如何在 Twitter 的 API 中使用Curesor参数,例如 -这里。我应该为每 100 个关注者进行一次新的 API 调用吗?

如果有人可以提供一个 PHP 示例来获取完整的追随者列表,我会很高兴,假设我有 100 多个...

提前致谢!

4

4 回答 4

2

您需要将光标值传回 API 以获取下一个“块”关注者。然后从该块中获取游标参数并将其传回以获取下一个块。它就像一个“获取下一页”机制。

于 2009-11-23T21:15:21.843 回答
1

尽管您前段时间问过,但我希望这将是更准确的答案。

  1. Twitter 不提供关于 next_cursor 含义的信息。只有光标如何工作
  2. 这只是 Twitter 管理分页的一种简单方法。
  3. «该功能旨在线性使用,每个用户一次设置一个光标。» 资源

«这对您来说可能效率较低,但对我们来说效率更高。» 推特员工

但是... 之前有人在断开的链接中问过“游标是持久的吗?似乎答案是“是”»

这意味着您可以将最后一个光标保存在 0 之前,并在下次继续使用它。

于 2017-04-01T21:11:11.933 回答
0

查看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());
      }

    }

  }
于 2009-11-23T21:16:01.903 回答
0

自从提出这个问题以来,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)))
于 2012-01-15T16:40:23.397 回答