jQuery: Mostrar el último Tweet con JSON

1 - , , - 05/02/2012 19:43:02

El siguiente snippet permite extraer el último tweet mediante jQuery y JSON.

$.getJSON("http://twitter.com/statuses/user_timeline/username.json?callback=?", function(data) {
     $("#twitter").html(data[0].text);
});

Donde username es el nombre de usuario del que deseamos extraer el último tweet. Por ejemplo:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery tweet</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
<script src="js/modernizr.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$.getJSON("http://twitter.com/statuses/user_timeline/webintenta.json?callback=?", function(data) {
     $("#twitter").html(data[0].text);
});
});	
</script>
<style type="text/css">
#twitter{
	padding:5px;
    font-family: Arial, Helvetica, Sans-serif;
	font-size:13px;
	color:#666;
	background:#E8E8E8;
	border:1px solid #CCC;
    width:300px;
    margin:0 auto;
}
</style>
</head>
<body>
<div id="twitter"></div>
</body>
</html>

Ver ejemplo en funcionamiento » »

Visto en CSS Tricks » »

Comentarios

paul09/05/2012 21:13:58

1
nice!

Deja tu comentario

  • El comentario debe estar relacionado con el contenido de la entrada.
  • Comentarios ofensivos, con spam o con lenguaje inapropiado serán eliminados.

captcha