2012-05-16 159 views
2

我知道如何使用API​​获取趋势,但我想按国家和前10名。获取国家顶级Twitter趋势

我该怎么办?那可能吗?

试过这一个,但没有工作

http://api.twitter.com/1/trends/current.json?count=50 
+0

这些方法不再有效。 API 1已过时,您必须通过身份验证才能使用API​​ 1.1。 – ananda

回答

8

是的,可以。

首先,找出你想得到的数据为which countries

调用

https://dev.twitter.com/docs/api/1/get/trends/available 

会给你所有的Twitter的趋势的国家名单。

假设您想要英国的趋势。上面告诉我们,WOEID是23424975.

要获得top ten trends的英国,可以拨打

https://api.twitter.com/1/trends/23424975.json 
+1

我想为印度,我得到了它> https://api.twitter.com/1/trends/23424848.json –

+0

这个答案不再工作。 API 1已过时。 – ananda

1

你需要弄清楚的第一woeids这里使用这个工具http://sigizmund.info/woeidinfo/,然后将其变得容易一个简单的功能

function get_trends($woeid){ 
     return json_decode(file_get_contents("http://api.twitter.com/1/trends/".$woeid.".json?exclude=hashtags", true), false); 
    } 

在这里,我为你写了一个简单的示例脚本。检查它在这里Twitter Trends Getter

希望它有帮助!

+0

我们可以在单个请求中获得多个$ woeid的趋势吗? –

11

请注意,Twitter API v1不再起作用。 Read announcement
所以你应该使用Twitter API 1.1。

REST方法是这样的:GET trends/place

https://dev.twitter.com/docs/api/1.1/get/trends/place 

你应该访问令牌认证达到这个数据。

+0

嗨,我已经在twitter中创建应用程序,并获得令牌和标题仍然“无法验证你”。邮件测试时在邮递员(http反应检查插件)..你能帮我这个吗? –