Skip to content

Instantly share code, notes, and snippets.

@roelven
Created July 21, 2010 07:39
Show Gist options
  • Save roelven/484195 to your computer and use it in GitHub Desktop.
Save roelven/484195 to your computer and use it in GitHub Desktop.
Get Twitter avatar via JSONP client-side
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
// Call the Twitter API after blurring the input field where a user entered his Twitter handle
// Get the avatar and append as picture in the HTML
$('#twittername').blur(function() {
console.log('Twitter call');
var tweeter = $('#twittername').val();
$.ajax({
type: 'GET',
processData: true,
url: 'http://api.twitter.com/1/users/show/' + tweeter + '.json',
dataType: 'jsonp',
success: function(results) {
console.log('Response!');
console.log(results.name);
console.log(results.profile_image_url);
console.log('<img src="' + results.profile_image_url + '" alt="'+ results.name +'" />');
$('.wrapper').append('<img src="' + results.profile_image_url + '" alt="'+ results.name +'" />')
return false;
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment