【问题标题】:PHP code for moving the cursor using the twitter API使用 twitter API 移动光标的 PHP 代码
【发布时间】:2012-11-12 00:21:14
【问题描述】:

所以我已经有一个脚本,它使用 xml 格式的 API 收集 twitter 用户的前 4999 个关注者 ID。我半理解游标过程是如何工作的,但我很困惑如何实现它以循环直到它收集所有关注者。我试图收集的用户将接听大约 8 个电话。关于如何实现游标循环的任何想法?

<?php
 $xmldata = 'http://api.twitter.com/1/followers/ids/microsoft.xml';
 $open = fopen($xmldata, 'r');
 $content = stream_get_contents($open);
 fclose($open);
 $xml = simplexml_load_file($xmldata);
 $cursor = $xml->next_cursor;
 $file = fopen ('output1.csv', 'w+');
fwrite($file, "User id\n\r");
 while($cursor =! 0)
 {
 foreach ($xml->ids->id as $id) 
 {
    fwrite($file, $id . ", ");
fwrite($file, "\n");


 }
 $xmldata = 'http://api.twitter.com/1/followers/ids.xml?cursor='. $cursor
.'&screeb_name=microsoft';
 ?>

【问题讨论】:

  • 可能需要更多信息才能回答您的问题...
  • 基本上我正在尝试使用 twitter API 检索 400,000 个关注者 ID。但是,一次调用只能检索 4999 个用户。我正在尝试找出如何收集其余的追随者。

标签: php twitter web-crawler


【解决方案1】:

让我以微软目前的追随者(34.6 万追随者)为例。

https://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=microsoft

它只获取 5000 个用户 ID,这是 twitter API 的限制。因此,您需要从 json 输出中获取 next_cursor 字符串

next_cursor_str":"1418048755615786027"

所以,你的下一个电话是

https://api.twitter.com/1/followers/ids.json?cursor=1418048755615786027&screen_name=microsoft

继续这样做,直到 next_cursor 为零。

当您一次又一次地这样做时,只需继续存储所有 id..

【讨论】:

  • 感谢您的回复,我已经更新了一些代码。它看起来像那样吗?
  • 如果你告诉我错误是什么,我可以帮你解决......我现在看到了代码......发现语法错误...... while($cursor != 0)跨度>
猜你喜欢
  • 1970-01-01
  • 2021-07-10
  • 2013-07-21
  • 1970-01-01
  • 2012-07-28
  • 2018-12-10
  • 1970-01-01
  • 2015-08-15
相关资源
最近更新 更多