Created
July 21, 2010 07:39
-
-
Save roelven/484195 to your computer and use it in GitHub Desktop.
Get Twitter avatar via JSONP client-side
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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