使用新API获取Twitter数据

时间:2013-03-26 06:03:26

标签: php json twitter

由于Twitter最近更新了其API,如何才能获得一个人的粉丝数量

我可以使用以下方法使用旧API获取此类数据,但如果我理解正确,它将随时停止工作。

http://api.twitter.com/1/statuses/user_timeline.json?screen_name=twitter

如何使用新API获取相同的数据?我检查了他们的文档,但无法理解。

2 个答案:

答案 0 :(得分:1)

straight from the new documentation看起来最大的区别就是使用1.1代替1

您仍然使用JSON检索数据 -

https://api.twitter.com/1.1/statuses/user_timeline.json

文档说要求是:

Always specify either an user_id or screen_name when requesting a user timeline.

返回的对象包含一个“user”对象,其中包含followers_count键:值对。

{
    {
        ......
        user: {
            .....
            "followers_count" : int
        }
    }
}

答案 1 :(得分:1)

是的,令人困惑。我最近为一位客户做了这件事,我花了一段时间才弄明白。

阅读本文:https://dev.twitter.com/docs/auth/application-only-auth

要遵守v1.1并获取所需数据,您需要通过Twitter帐户创建一个Twitter应用程序。该应用程序将为您提供几个访问密钥。您将使用这些访问密钥来获取访问令牌,您可以使用它来获取公共数据。

以下是我使用的实现:https://gist.github.com/luk3thomas/5243493