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?


For Facebook the image is publically availible and can be seen at:

For example, here is mine:

You will notice that the url above actually gets forwarded to another caching url. Don't save the long url ( save the short 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="//" />

Which gets you:

Thats it, no complicated API or authentication is needed.

For twitter you need to use the api:

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!

Some programming paradigms (Razor in ASP.NET or ASP.NET MVC 3, for example) have their own helpers to work with social media. If the paradigm you are programming in does not have helpers, you will have to access the FaceBook and/or Twitter APIs and use them to get the "avatar".

I have not played with Facebook, but the Twitter avatar link is provided on the user's profile, when you get it.

With regards twitter, I was able to get mine by visiting my profile page:<USERNAME>

From there, you locate the <a> tag with the class ProfileAvatar-image and extract the href attribute. I was able to use that link on a separate site to import my avatar from Twitter.

I did all this manually, but it would be relatively easy to set up a script that used the username to request the profile page and isolate that link.

Need Your Help

Codeigniter how to html template for emails

codeigniter email templates

I'm using below code to send email from my codeigniter based website's contact form, to do that i'm using below codes in my controller,