【问题标题】:Twitter API - Get WOEID specific trend words using Jquery and Json?Twitter API - 使用 Jquery 和 Json 获取 WOEID 特定趋势词?
【发布时间】:2012-04-30 09:37:54
【问题描述】:

我正在尝试使用 Jquery 获取来自特定国家(爱尔兰)的热门话题列表。 当我运行以下它的工作正常:

<script>
$(document).ready(function() {
$.ajax({
    url:'http://api.twitter.com/1/trends/current.json?callback=?',
    dataType:'json',
    success:function(data){
        $.each(data.trends, function(i){
            console.log(data.trends);
         });
    } });
 });
</script>

但是当我使用爱尔兰 WOEID (23424803) 代替“当前”时,我收到以下错误:

未捕获的类型错误:无法读取未定义的属性“长度”

有谁知道为什么它适用于“当前”而不适用于 WOEID?

提前致谢

【问题讨论】:

  • 你在说什么WOEID,什么current ..可能粘贴了错误的代码..
  • 如果你阅读了 twitter 文档就很清楚了,尽管这个问题并不是独立存在的(不是必须的)。 OP 正在谈论的woeid 是 23424803,而代替 current 的 url 将只是 http://api.twitter.com/1/trends/23424803.json。我在下面发布了问题的解决方案

标签: jquery json twitter


【解决方案1】:

通过查看http://api.twitter.com/1/trends/23424803.json,您遇到的唯一问题是链接返回了不同格式的 json 响应。首先使用jsonp,然后像这样调整你的代码:

$(document).ready(function() {
    $.ajax({
        url: 'http://api.twitter.com/1/trends/23424803.json',
        dataType: 'jsonp',
        success: function(data){
            $.each(data[0].trends, function(i){
                console.log(data[0].trends[i]);
            });
        }
    });
});

查看工作小提琴:http://jsfiddle.net/Bg9jU/9/

【讨论】:

  • 没有问题。如果它解决了您的问题,请接受答案,以便其他人知道它很有用。
猜你喜欢
  • 2011-06-12
  • 1970-01-01
  • 2021-03-08
  • 1970-01-01
  • 2018-04-01
  • 2013-06-06
  • 2016-03-29
  • 2016-12-16
  • 2014-09-17
相关资源
最近更新 更多