Skip to content

Instantly share code, notes, and snippets.

@embedly
Created May 3, 2010 17:19
Show Gist options
  • Save embedly/388335 to your computer and use it in GitHub Desktop.
Save embedly/388335 to your computer and use it in GitHub Desktop.
Simple example of Twitter Search with Embedly
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://scripts.embed.ly/jquery.embedly.js"></script></head>
<body>
<form action="" method="get"><input type="text" name="q"/><input type="submit" name="q" value="Search"/></form>
<ul></ul>
<script>
function searchTwitter(q){
//Force twitter to only search image providers
q += " twitpic OR yfrog OR flic.kr OR tweetphoto OR twitgoo OR post.ly OR tumblr.com OR moby.to OR imgur filter:links"
$.ajax({url : "http://search.twitter.com/search.json?q="+escape(q)+"&rpp=20&callback=?",
success : function(data){
$.each(data.results, function(index, obj){
//Find a url in the status
var p = obj.text.match(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig);
if (p != null){
var u = p[0].replace(' ', '');
//Call Embedly
$.embedly(u, {maxWidth:500}, function(oembed){
//Make sure it's a photo and add it to the list.
if (oembed != null && oembed.type == "photo")
$("UL").append('<li>'+oembed.code+'</li>');
});
}
});
},
dataType: "json"});
}
$(document).ready(function() {
$("form").bind("submit", function(e){e.preventDefault();$("UL").html('');searchTwitter($(this).children("INPUT[name=q]").val())});;
});
</script></body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment