Play

Display a Twitter Profile using YQL & jQuery

Jocelyn

With YQL (Yahoo! Query Language), you can access data from multiple sources using a SQL-like language that lets you query, filter and join data. If you're already familiar with SQL syntax, using YQL should be fairly straight-forward.

select * from twitter.user.profile where id='screen_name'

If you run this code in the YQL console you'll see that it grabs the relevant table from Twitter and returns the profile as XML or JSON.

Using jQuery you can use getJSON() to run the query and return the JSON response to your application.

$(document).ready(function() {

  // YQL query (url encoded)
  var url = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20twitter.user.profile%20where%20id%3D'screen_name'&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';

  // load the JSON data from the YQL query url
  $.getJSON(url, function(data) {

    // check that we have data
    if (!data.query.results) {
      return;
    }
   
    // do something with the JSON response...
  });

});

Demo

Enter a Twitter screen name and display a Twitter profile using YQL & jQuery.

Add comment

  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags
  • Use one of the forms name.module, name.theme, name.translation, name.installprofile or name.project, in order to link to http://drupal.org/project/name. Note that a link will be generated even if a project does not exist
  • Lines and paragraphs break automatically
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link
  • Websites and email addresses turn into links automatically
  • Insert Google Map macro
  • You may insert videos with [video:URL]
Your email will not be displayed publicly. If you have a Gravatar account, used to display your avatar.

jsfwd on Twitter 

@jsfwd on Twitter »
i heart jQuery
RSS Feed