Skip to content

Instantly share code, notes, and snippets.

@ArupSen
Created November 19, 2012 12:17
Show Gist options
  • Save ArupSen/4110355 to your computer and use it in GitHub Desktop.
Save ArupSen/4110355 to your computer and use it in GitHub Desktop.
Grab Twitter Feed
/* Grab Twitter Feed
Look at the url of the api that will change to /1.1 from march 2013
callback=twitterCallback2 still works
http://twitter.com/statuses/<username>.json? no longer works
*/
function init_twitter() {
$.getJSON('https://api.twitter.com/1/statuses/user_timeline.json?screen_name='+ twitterID +'&count=1&callback=?&include_rts=true', function(data){
var tweet = data[0];
var tweetID = tweet.id_str;
var tweetText = linkifyTweet(tweet.text);
var timeago = relativeTime(tweet.created_at);
var permalink = 'http://twitter.com/pixelunion/status/' + tweetID;
var fullname = tweet.user.screen_name;
var output = $('<p class="tweet">' + tweetText + '</p>');
var timestamp = $('<a class="timestamp accent-text" href="' + permalink + '" time="' + tweet.created_at + '" target="_blank">' + timeago + '</a>');
var user = $('<a href="http://www.twitter.com/'+ twitterID +'" class="twitter-name">'+ fullname +'</a>');
var twitter_avatar = $('<img src="'+ tweet.user.profile_image_url_https +'">');
output.appendTo('.tweet-area');
user.appendTo('.twitter-names');
timestamp.appendTo('.twitter-names');
twitter_avatar.appendTo('.twitter-avatar');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment