Fork me on GitHub

Get Twitter profile data with jQuery ajax, super easy!

Update:The following technique is also available as a Hovercard plugin.


We’ll use Twitter REST API in json format to look up any twitter user by its username. We’ll create a twitter card for President Barack Obama (@barackobama) as an example:

Resource url
http://api.twitter.com/1/users/lookup.json?screen_name=barackobama 
We’ll make an ajax request to this url.

Ajax request:

$.ajax({
    url'http://api.twitter.com/1/users/lookup.json?screen_name=barackobama&callback=?',
    type'GET',
    dataType'json',
    successfunction (data{
       //Profile name will be data[0].name 
       //Location will be data[0].location
       //Profile pic will be data[0].profile_image_url
       //Bio will be data[0].description
       //Tweets will be data[0].statuses_count
       //Followers will be data[0].followers_count
       //Visit https://dev.twitter.com/docs/api/1/get/users/lookup for all options
   
    }

 });    

Live Demo: (including html and css for twitter card)

1 note

  1. designwithpc posted this
blog comments powered by Disqus