Getting a facebook profile picture from an email address

隐身守侯 提交于 2019-11-30 12:06:55

问题


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?


回答1:


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




回答2:


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.




回答3:


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...



来源:https://stackoverflow.com/questions/3129910/getting-a-facebook-profile-picture-from-an-email-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!