Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a link to a Facebook or Twitter avatar by username?

How can I get a link to a Facebook or Twitter avatar by username?

like image 338
Jamey McElveen Avatar asked Jan 18 '11 16:01

Jamey McElveen


2 Answers

For Facebook the image is publically availible and can be seen at: http://graph.facebook.com/username/picture

For example, here is mine: http://graph.facebook.com/totten/picture

You will notice that the url above actually gets forwarded to another caching url. Don't save the long url (http://profile.ak.fbcdn.net/....) save the short http://graph.facebook.com/ one. The other, longer url, could change and break.

If you want to display that url in a web page you just need to do the following:

<img src="//graph.facebook.com/totten/picture" />

Which gets you: http://graph.facebook.com/totten/picture

Thats it, no complicated API or authentication is needed.

For twitter you need to use the api: http://apiwiki.twitter.com/w/page/22554755/Twitter-REST-API-Method:-users%C2%A0show

like image 75
Nathan Totten Avatar answered Nov 01 '22 13:11

Nathan Totten


you have to use facebook's graph API to get profile pictures. You'll have to register your app with facebook to get an API key, and then you can access most of the information on a given user's profile.check out their developer page to see some examples

Twitter just changed the way they handle API call. Looks like you'll have to register your app with them as well to get access to the avatars. I haven't used the twitter API since they changed it, so i'm not a sure about what goes on, but check out the docs page to read up on what you'd have to do.

hope this helps!

like image 22
heymrcarter Avatar answered Nov 01 '22 13:11

heymrcarter