【问题标题】:how to get trends from twitter about a specific location如何从 Twitter 获取有关特定位置的趋势
【发布时间】:2011-05-22 19:41:04
【问题描述】:

我正在尝试为我的申请获取特定位置的 Twitter 趋势,比如来自英国的“布里斯托尔”。

问题是,现在我们只能获取 twitter API 中提到的美国国家和一些城市的趋势。但我只是想知道这个网站怎么样

http://trendsmap.com/local/gb/bristol

即使没有在 Twitter 趋势 API 中列出,也正在获取大多数国家和城市的趋势。

请帮助解决这个问题

问候, 苏库玛

【问题讨论】:

标签: twitter


【解决方案1】:

我整理了一个不错的 JS fiddle,它可以回答您在处理 Twitter API 时的所有问题。该网络应用程序抓取热门地区,并允许您深入了解热门话题,然后查看其中的推文。

我还包括了一个标准的 Twitter 搜索提交框,所以奇怪的是,这是一个准系统 Tweetdeck 客户端供您检查。此外,为了推动新 Jquery 库的适配,我使用了 1.91,它使用了新的 live.bind 点击事件语法。

享受

http://jsfiddle.net/jdrefahl/5M3Gn/

function searchTwitter(query) {
$.ajax({
    url: 'http://search.twitter.com/search.json?' + jQuery.param(query),
    dataType: 'jsonp',
    success: function (data) {
        var tweets = $('#tweets');
        tweets.html('');
        for (res in data['results']) {
            tweets.append('<div>' + data['results'][res]['from_user'] + ' wrote: <p>' + data['results'][res]['text'] + '</p></div><br />');
        }
    }
});

}

$(document).ready(function () {

function getTrendsByID(id) {
    $.ajax({
        url: 'http://api.twitter.com/1/trends/' + id + '.json',
        dataType: 'jsonp',
        success: function (data) {
            $.each(data[0].trends, function (i) {
            });
        }
    });
};

function getLocales() {
    $.ajax({
        url: 'https://api.twitter.com/1/trends/available.json',
        dataType: 'jsonp',
        success: function (data) {
            var locales = $('ul#locales');
            locales.html('');
            $.each(data, function (i) {
                localeID[i] = data[i].woeid;
                $('ul#locales').append('<li>' + data[i].name + '</li>');
            });
        }
    });

};

function getTrends(id) {
    $.ajax({
        url: 'https://api.twitter.com/1/trends/' + id + '.json',
        dataType: 'jsonp',
        success: function (data) {
            var trends = $('ul#currentTrends');
            trends.html('');
            $.each(data[0].trends, function (i) {
                $('ul#currentTrends').append('<li>' + data[0].trends[i].name + '</li>');
            });
        }
    });
};

// Event Handlers
$(document).on("click", "#locales li", function () {
    var $this = $(this);
    var localesHdr = $('#currentTrendsCont h3');
    var tweets = $('#tweets');
    var trendsHdr = $('#tweetsCont h3');
    trendsHdr.html('');
    tweets.html('');
    localesHdr.html('');
    $('#currentTrendsCont h3').html($this.text());
    getTrends(localeID[$this.index()]);
});

$(document).on("click", "#currentTrends li", function () {
    var $this = $(this);
    var trendsHdr = $('#tweetsCont h3');
    trendsHdr.html('');
    $('#tweetsCont h3').html($this.text());
    var params = {
        q: $this.text(),
        rpp: 10
    };
    searchTwitter(params);
});

$('#submit').click(function () {
    var trendsHdr = $('#tweetsCont h3');
    var trends = $('#currentTrends');
    var local = $('#currentTrendsCont h3');
    local.html('');
    trendsHdr.html('');
    trends.html('');
    $('#tweetsCont h3').html('search query: '+$('#query').val());
    var params = {
        q: $('#query').val(),
        rpp: 10
    };
    searchTwitter(params);
});

// Globals
var localeID = new Array();

// Init!
getLocales();

});

【讨论】:

  • 是否有可能从 twitter 获得最低趋势的推文
【解决方案2】:

【讨论】:

猜你喜欢
  • 2017-02-11
  • 1970-01-01
  • 2011-06-12
  • 2018-04-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-06
  • 1970-01-01
  • 2021-03-08
相关资源
最近更新 更多