2010-12-09 127 views
0

我正在嘗試從我的應用程序獲取來自英國的「Bristol」特定位置的Twitter趨勢。如何從twitter獲取關於特定位置的趨勢

問題是,現在我們可以獲得twitter API中提及的僅適用於國家和美國的一些城市的趨勢。但我只是想知道像

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

該網站是如何得到的趨勢大多數國家和城市,即使他們沒有在Twitter的趨勢API上市。

搞清楚這個

問候請幫幫忙, 薩庫馬爾

+0

感嘆............ – Yehonatan 2010-12-09 11:46:07

+0

檢查這個答案︰http://stackoverflow.com/questions/10616017/getting-top-twitter-trends-by-country/17107785#17107785 – trante 2013-06-15 11:35:28

回答

0
+0

我嘗試使用WOEID的布裏斯托爾(布裏斯托爾WOEID = 13963)使用下面,但它給頁面沒有找到錯誤 http://api.twitter.com/1/trends/13963.xml – JavaGeek 2010-12-11 05:41:59

2

我把一個漂亮的JS提琴應該回答你所有的問題,當談到與Twitter的API。該Web應用抓取熱門地區,並允許您深入探究趨勢主題,然後查看其中的推文。

我還包括一個標準的Twitter搜索提交框,所以以一種奇怪的方式,這是一個準系統Tweetdeck客戶端,供您檢查。另外,爲了推動新的Jquery庫的適應性,我使用了1.91新的live.bind click事件語法的實用工具。

享受

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 />'); 
     } 
    } 
}); 

}

$(文件)。就緒(函數(){

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(); 

});

相關問題