15

I'm trying to get a user's facebook profile picture based on their email address. Effectively, I want to offer my users the option between using Gravatar for their image, or Facebook. However, the only way I know of to get a user's facebook image is via:

http://graph.facebook.com/[FBOOK USERNAME]/picture?type=large

Since the usernames may vary between facebook and my site, I would like to do this via email address rather than username. How do I query for someone's facebook profile picture via email address?

Mala
  • 14,178
  • 25
  • 88
  • 119
  • Can you really do that? It seems a bit of a security issue to enable retrieval of facebook data based on an email address that is likely private user data. Of course, facebook's definition of private may be looser than others'. – Chris Farmer Jun 28 '10 at 03:35
  • I'm looking for the same thing. I thought about using the user.name in the url but that only works if a user has set up a facebook username on www.facebook.com/username. – Jorre Feb 27 '11 at 23:20
  • It seems the Sparrow (http://sparrowapp.com/) email client is doing this however it requires you to authenticate against facebook. – Levi Putna Apr 10 '12 at 02:46

3 Answers3

24

I see this question has a couple of years already but the same search approach can be taken using the Graph API:

GET https://graph.facebook.com/search?q={EMAIL}&type=user

You can try this on the Graph API Explorer. You don't get the profile picture directly but you get the user id which you can easily use to get the public profile picture.

https://graph.facebook.com/{UID}/picture

urraka
  • 997
  • 7
  • 9
  • Exactly - excellent answer. :) The thing that a lot of people miss is that, when using the Graph API in this way, you're limited to getting the *public* profile picture. If a user's settings are such that their profile picture is private, you won't be able to get it (which, I think most of us would agree, is how it should be). – LloydDobbler Jan 02 '13 at 17:25
  • 10
    it says "A user access token is required to request this resource" – Adeem Feb 28 '14 at 02:18
  • 5
    not possible to search in this way anymore - must have been abused way too much unfortunately – Simon_Weaver Aug 23 '16 at 03:14
5

There doesn't seem to be an official way to do what you are asking. It seems like facebook has made this closed on purpose, probably something to do with privacy. Its actually really easy to do this in a few screen-scraping steps though:

  1. Visit http://www.facebook.com/#!/search.php?q=#{USERS_EMAIL_ADDRESS}&type=all&init=srp

  2. If page returns "No results found for your query.", then they don't have a profile.

  3. Otherwise, the page will contain a thumbnail of the user for that email address. (something like http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs227.ash2/48219_72120057_3223_q.jpg)

I could write a sinatra app to do this in about 5 minutes, if anyone would like me to.

But I think gravatar and facebook should just be friends.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
ndbroadbent
  • 13,513
  • 3
  • 56
  • 85
  • 1
    I really do like this - I wouldn't screen-scrape but I can definitely use the search results to automatically get users' facebook-IDs, and use the method in my question. However, searching only seems to work when you're logged in, which defeats me doing this programatically – Mala Dec 02 '10 at 06:02
-2

What you're asking to do is part of why Facebook Connect exists.

Using their not-too-cleverly-named XFBML you can request the image directly: <fb:profile-pic uid="1256100362" facebook-logo="true" size="thumb"> </fb:profile-pic>

But you have to implement logins with FB Connect first...

Nilloc
  • 845
  • 7
  • 20
  • 1
    this still uses the UID though - you can already do that without Facebook Connect via, in the case you mentioned, http://graph.facebook.com/1256100362/picture?type=large – Mala Jun 28 '10 at 04:01
  • 3
    yup, it's a shame that we can't do that with an md5(email) just like gravatar does – Jorre Feb 27 '11 at 23:21