Twitter收藏夹和超过20个

时间:2010-03-21 10:30:28

标签: php twitter

我使用curl来获取我的Twitter收藏夹:

<?php
$username = "bob";
$password = "password";
$twitterHost = "http://twitter.com/favorites.xml";
$curl;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_URL, $twitterHost);
$result = curl_exec($curl);
curl_close($curl);
header('Content-Type: application/xml; charset=ISO-8859-1');
print $result;
?>

然而,这仅取得最后20个收藏夹,而不是所有收藏夹。

如果我修改这一行:

$twitterHost = "http://twitter.com/favorites.xml";

并将其更改为:

$twitterHost = "http://twitter.com/favorites.xml?page=2";

我可以获得下一组20个收藏夹。

无论如何,使用Twitter API似乎无法找出有多少收藏页面。

因此,任何人都可以建议获得所有收藏的最佳方式吗?

或者,如果无法做到这一点,请获取所有推文的日期范围?

1 个答案:

答案 0 :(得分:2)

您应该可以调用此API函数:

http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users%C2%A0show

此API调用“users / show”返回具有此信息的属性“favourites_count”。例如,转到此页面查看,将“bob”替换为您的用户名:

http://api.twitter.com/1/users/show/bob.xml