I basically would like to figure out if I could search for all tweets that talks about a url, for example, http://twitter.com/blah. I开发者_开发百科deally the search should also count the shortened url. Any pointers?
http://backtweets.com/
This service apparently is able to search across shortened urls..
You may want to look into the Twitter API Documentation documentation which includes a search method.
Your request to also search for shortened URLs is curious, though - I understand why you might want to do that but I can't imagine how you believe it might work. Since Twitter itself doesn't hold the expanded version of a short URL, there wouldn't be any way to use the Twitter search function to look for shortened links. And since you can't predict which URL shortener people might use, you won't know what to look for anyway.
Topsy's Otter API provides this functionality: http://code.google.com/p/otterapi/wiki/Resources#/linkposts
I would suggest just using the Twitter Key/Word as your key for your submission to search. In this JS Fiddle I created you will see how I extract the "Query keyword" from the trending topics that I spawned from a trending locales call. I grab the yahoo WOEID from the local results and use that spawn local trends for that specific Geographical area. Form there, the Trending tweets all have a "Query String" that can be captured and added to the Twitter search paramas object which will spit out the tweets for that trending topic within that trending local. I really hope this helps because I wrote it to be a straight forward Jquery as possible. Enjoy.
Hey guys, I put together a nice JS fiddle that should answer all your questions when it comes to dealing with the Twitter API. The webapp grabs the trending locales, and allows you to drill down to the trending topics, and then see the Tweets within.
I also included a standard Twitter search submission box, so in a weird way, this is a barebones Tweetdeck client for you to examine. Also, to push the adaption of the new Jquery libraries, I have used 1.91 which utilities the new live.bind click event syntax.
Enjoy
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();
});
精彩评论