Réseaux sociaux

De Marmits Wiki

Récupérer les derniers tweets d'un compte en Jquery

<ul class="tweets"></ul>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">

/*
 Taken from http://www.sitepoint.com/blogs/2009/04/21/make-your-own-web-site-badges-with-jquery-and-json/
 I've made some minor adjustments to make it easier to configure, and I've altered the output format too.

 If you're using this "as-is", make sure you have a <ul class="tweets"></ul> to drop your tweets into.
*/

twitter_user  = 'marmitscom';
twitter_count = 10;

twitter_url = "http://twitter.com/status/user_timeline/" + twitter_user + ".json?count=" + twitter_count + "&callback=?";

$.getJSON(twitter_url, function(data) {
 $.each(data, function(i, item) {
 var txt = item.text
 .replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig, '<a href="$1">$1</a>')
 .replace(/@+([_A-Za-z0-9-]+)/ig, '<a href="http://twitter.com/#!/$1">@$1</a>')
 .replace(/#+([_A-Za-z0-9-]+)/ig, '<a href="http://search.twitter.com/#!/search/$1">#$1</a>');

 $('<li>' + txt + '</li>').appendTo('ul.tweets');
 });
});
</script>