Search code examples
facebooktwitter

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?


Solution

  • 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