Reputation: 6512
Is there an easy way to grab a users twitter image with a simple line such as:
http://www.twitter.com/USERID/picture
If there isn't, what could I possibly look into that has an easy method to grab the user profile image?
Upvotes: 1
Views: 2520
Reputation: 75317
UPDATE February 2014: The original answer no longer works now v1 of Twitters API has been retired. The below is the nearest substitute for what was asked, but for v1.1 of the API.
Version 1 of the Twitter API allowed you to do this easily, using a URL such as http://api.twitter.com/1/users/profile_image/:screen_name.format
however that was retired in May 2013.
As of Verson 1.1, you cannot get a users profile picture URL without making an authenticated call. Once you have got an authenticated user, simply make a request to any endpoint which returns a users information (such as /user/show
), and use the "profile_image_url";
jQuery.ajax('/users/show', {
data: {
screen_name: 'mattlunn'
},
headers: {
// All your OAUTH headers
}
}).done(function (res) {
var url = res.profile_image_url;
var img = document.createElement("img");
alert("URL is '" + url + "'");
img.src = url;
document.body.appendChild(img);
});
Upvotes: 5