Display a Twitter Profile using YQL & jQuery
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
jsfwd on Twitter
- Must see... Arcade Fire's new HTML5 music experience 'The Wilderness Downtown' http://bit.ly/cVcoDy 4 days 16 hours ago
- Drupal Camp Toronto 2010 - October 15 & 16 - http://2010.drupalcamptoronto.org 2 weeks 20 hours ago
- Rob Ford "I can't support bike lanes" when cyclists get hit "it's their own fault" http://youtu.be/nySs1cEq5rs #voteTO #bikeTO 2 weeks 4 days ago
- @jswaby me thinks I'll keep it ;) 2 weeks 5 days ago
- Found a BlackBerry Bold & chargers in the recycling this morning. Recycling #fail. Me #win. 2 weeks 5 days ago
- #MMA coming to Ontario in 2011 (it's about time) http://bit.ly/ddK6AY 2 weeks 5 days ago
- Twitter Tweet Button for Drupal http://t.co/FaAAnTD via @jsfwd 2 weeks 6 days ago
- Twitter reclaiming the Tweet button http://bit.ly/cjwYie 3 weeks 2 days ago
- RT @paulosman: Next #OpenWebTO meeting is on August 30th at #csiTO! Come learn about the #Salmon protocol from @walkah http://bit.ly/dtAdKp 3 weeks 3 days ago
- @DilbertDave Some Drupal contrib modules need to be patched to work with PHP 5.3. If you can use 5.2.x. 3 weeks 5 days ago