检索只有电子邮件地址的 Facebook / Google+ / Linkedin 个人资料图片
Retrieving Facebook / Google+ / Linkedin profile picture having email address only
我需要什么
我需要为只知道其电子邮件地址的用户自动查找和下载个人资料图片。最初,考虑到活跃使用它的人数,我专注于 Facebook。但是,他们的 API 似乎不再提供直接支持。
这里有类似的问题:
How to get a facebook user id from the login email address 已经过时了,目前的答案有 "it's deprecated" / "it's not possible"...
编辑:我发现了更好的问题:Find Facebook user (url to profile page) by known email address(实际上解释了为什么以及从何时开始不支持此功能)
一定有办法...
让我认为这应该是可能的是 Spokeo 正在以某种方式做到这一点:
http://www.spokeo.com/email-search/search?e=beb090303%40hotmail.com
有些服务/API提供这种功能:
Clearbit
Pipl
...但我还没有找到任何免费的东西。
备选方案
如果有一些解决方法或不同于使用 Facebook API 的方法来实现此目的,我想知道。如果 Facebook 在这里真的完全没有希望,那么这些组合:Google+, Linkedin and/or Gravatar 可以。
我的第一次(原创)尝试:
一旦您有了 Facebook 的用户名或用户 ID,就可以轻松构建 URL 下载图片。因此,我尝试使用带有 /search
图 API:
的电子邮件来查找 Facebook 的用户 ID
https://graph.facebook.com/search?q=beb090303@hotmail.com&type=user&access_token=TOKEN
不幸的是,它总是以 "A user access token is required to request this resource."
结尾
使用 FB PHP API + FB App ID & Secret
我也试过这个:起初我使用应用程序 ID 和秘密检索 access_token
然后我试图将它用作 /search
请求的一部分 curl
:
function post_query_url($url, $data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function get_query_url($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
function get_retrieve_app_access_token($app_id, $secret) {
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.$app_id.'&client_secret='.$secret.'&grant_type=client_credentials';
$res = get_query_url($url);
if (!empty($res)) {
$tokens = explode('=', $res);
if (count($tokens) == 2)
return $tokens[1];
}
return null;
}
function post_retrieve_app_access_token($app_id, $secret) {
$url = 'https://graph.facebook.com/oauth/access_token';
$data = 'client_id='.$app_id.'&client_secret='.$secret.'&grant_type=client_credentials';
$res = post_query_url($url, $data);
if (!empty($res)) {
$tokens = explode('=', $res);
if (count($tokens) == 2)
return $tokens[1];
}
return null;
}
function get_id_from_email($email, $accessToken) {
$url = 'https://graph.facebook.com/search?q='.urlencode($email).'&type=user&access_token='.$accessToken;
$res = get_query_url($url);
if (!empty($res)) {
return $res;
}
return null;
}
echo 'Retrieving token...<br>';
$token = post_retrieve_app_access_token('MY_APP_ID', 'SECRET');
echo 'Retrieved token: ' . $token . '<br>';
echo 'Retrieving user ID...<br>';
$id = get_id_from_email('beb090303@hotmail.com', $token);
echo 'Retrieved ID: ' . $id . '<br>';
输出类似:
Retrieving token...
Retrieved token: 367458621954635|DHfdjCnvO243Hbe1AFE3fhyhrtg
Retrieving user ID...
Retrieved ID: {"error":{"message":"A user access token is required to request this resource.","type":"OAuthException","code":102}}
其他信息
因为它要求"user access token",我也试过去 Facebook 的 Graph Explorer:https://developers.facebook.com/tools/explorer/
让它为我生成访问令牌并查询:
search?q=beb090303@hotmail.com&type=user&debug=all
结尾为:
{
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
}
...所以 Facebook 在这里似乎有点绝望。
有一个错误:Can't search for user by email after July 2013 Breaking Changes 已作为 "By Design" 关闭,官方回复:
"The ability to pass in an e-mail address into the "user" search type was removed on July 10, 2013. This search type only returns results that match a user's name (including alternate name)" ~ Joseph Tuấn Anh Phan (Facebook Team)
所以可能没有来自 Graph API 的直接支持。
我试过 Graph API Explorer 你也可以尝试使用一些 FQL(只需要 select 2.0 版,因为不再支持较新的版本),不幸的是查询如下:
SELECT uid, name FROM user where email = 'some.email@gmail.com'
给出:
"error": {
"message": "(#604) Your statement is not indexable. The WHERE clause must contain
an indexable column. Such columns are marked with * in the tables linked from
http://developers.facebook.com/docs/reference/fql ",
"type": "OAuthException",
"code": 604
}
and reference for table user表示在WHERE
中只能使用uid
和third_party_id
。
这正是 Gravatar 存在的原因以及人们使用 Gravatar 的原因,用户知道他们将哪个 public 个人资料图像绑定到哪个电子邮件地址,并且他们知道在哪里更改它。
您的应用可以让用户上传自己的个人资料图片并回退到 Gravatar。
如果您只是尝试从 Facebook 或 Google+ 中提取图片,这可能会吓坏您的用户,而且他们也更难知道您的服务从何处获取个人资料图片。
在PHP中使用Gravatar就这么简单:
<?php
$email = "email@server.com";
$default = ""; // absolute url to default image goes here or leave empty for default gravatar image
$size = 200;
$grav_url = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?d=" . urlencode($default) . "&s=" . $size;
header("content-type: image/jpeg");
echo file_get_contents($grav_url);
?>
除此之外,您还可以使用 Facebook and/or Google+ 作为外部登录提供程序,用户可以在其中授予您的应用程序访问其个人资料信息的权限。
您应该需要访问令牌以及用户的 Facebook id。在不知道他们的情况下无法获取他们的个人资料照片
我认为 Spokeo 可能与 Facebook 达成了访问数据的协议?我不会感到惊讶。
无论如何,如果您在个人资料中,您可以在 HTML 中搜索 profile_id
。这是一个 hack,不确定它是否有效。
您始终可以允许人们通过使用他们的 g+/facebook/whatever 帐户登录来发表评论(不过需要您做一些类似 OpenID 的事情);如果他们已经登录,您应该能够获得 facebook uid。
此外,还有一个叫做 libravatar 的东西,它允许人们将图片与他们的 OpenID 或 电子邮件地址相关联(如果他们没有,它会回退到 gravatar专门为 libravatar 配置了任何东西);使用它应该会给你更多的照片,而不是你坚持使用 "just" gravatar。
我需要什么
我需要为只知道其电子邮件地址的用户自动查找和下载个人资料图片。最初,考虑到活跃使用它的人数,我专注于 Facebook。但是,他们的 API 似乎不再提供直接支持。
这里有类似的问题: How to get a facebook user id from the login email address 已经过时了,目前的答案有 "it's deprecated" / "it's not possible"... 编辑:我发现了更好的问题:Find Facebook user (url to profile page) by known email address(实际上解释了为什么以及从何时开始不支持此功能)
一定有办法...
让我认为这应该是可能的是 Spokeo 正在以某种方式做到这一点: http://www.spokeo.com/email-search/search?e=beb090303%40hotmail.com
有些服务/API提供这种功能:
Clearbit
Pipl
...但我还没有找到任何免费的东西。
备选方案
如果有一些解决方法或不同于使用 Facebook API 的方法来实现此目的,我想知道。如果 Facebook 在这里真的完全没有希望,那么这些组合:Google+, Linkedin and/or Gravatar 可以。
我的第一次(原创)尝试:
一旦您有了 Facebook 的用户名或用户 ID,就可以轻松构建 URL 下载图片。因此,我尝试使用带有 /search
图 API:
的电子邮件来查找 Facebook 的用户 ID
https://graph.facebook.com/search?q=beb090303@hotmail.com&type=user&access_token=TOKEN
不幸的是,它总是以 "A user access token is required to request this resource."
结尾 使用 FB PHP API + FB App ID & Secret我也试过这个:起初我使用应用程序 ID 和秘密检索 access_token
然后我试图将它用作 /search
请求的一部分 curl
:
function post_query_url($url, $data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
function get_query_url($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
function get_retrieve_app_access_token($app_id, $secret) {
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.$app_id.'&client_secret='.$secret.'&grant_type=client_credentials';
$res = get_query_url($url);
if (!empty($res)) {
$tokens = explode('=', $res);
if (count($tokens) == 2)
return $tokens[1];
}
return null;
}
function post_retrieve_app_access_token($app_id, $secret) {
$url = 'https://graph.facebook.com/oauth/access_token';
$data = 'client_id='.$app_id.'&client_secret='.$secret.'&grant_type=client_credentials';
$res = post_query_url($url, $data);
if (!empty($res)) {
$tokens = explode('=', $res);
if (count($tokens) == 2)
return $tokens[1];
}
return null;
}
function get_id_from_email($email, $accessToken) {
$url = 'https://graph.facebook.com/search?q='.urlencode($email).'&type=user&access_token='.$accessToken;
$res = get_query_url($url);
if (!empty($res)) {
return $res;
}
return null;
}
echo 'Retrieving token...<br>';
$token = post_retrieve_app_access_token('MY_APP_ID', 'SECRET');
echo 'Retrieved token: ' . $token . '<br>';
echo 'Retrieving user ID...<br>';
$id = get_id_from_email('beb090303@hotmail.com', $token);
echo 'Retrieved ID: ' . $id . '<br>';
输出类似:
Retrieving token...
Retrieved token: 367458621954635|DHfdjCnvO243Hbe1AFE3fhyhrtg
Retrieving user ID...
Retrieved ID: {"error":{"message":"A user access token is required to request this resource.","type":"OAuthException","code":102}}
其他信息
因为它要求"user access token",我也试过去 Facebook 的 Graph Explorer:https://developers.facebook.com/tools/explorer/
让它为我生成访问令牌并查询:
search?q=beb090303@hotmail.com&type=user&debug=all
结尾为:
{
"error": {
"message": "(#200) Must have a valid access_token to access this endpoint",
"type": "OAuthException",
"code": 200
}
}
...所以 Facebook 在这里似乎有点绝望。
有一个错误:Can't search for user by email after July 2013 Breaking Changes 已作为 "By Design" 关闭,官方回复:
"The ability to pass in an e-mail address into the "user" search type was removed on July 10, 2013. This search type only returns results that match a user's name (including alternate name)" ~ Joseph Tuấn Anh Phan (Facebook Team)
所以可能没有来自 Graph API 的直接支持。
我试过 Graph API Explorer 你也可以尝试使用一些 FQL(只需要 select 2.0 版,因为不再支持较新的版本),不幸的是查询如下:
SELECT uid, name FROM user where email = 'some.email@gmail.com'
给出:
"error": {
"message": "(#604) Your statement is not indexable. The WHERE clause must contain
an indexable column. Such columns are marked with * in the tables linked from
http://developers.facebook.com/docs/reference/fql ",
"type": "OAuthException",
"code": 604
}
and reference for table user表示在WHERE
中只能使用uid
和third_party_id
。
这正是 Gravatar 存在的原因以及人们使用 Gravatar 的原因,用户知道他们将哪个 public 个人资料图像绑定到哪个电子邮件地址,并且他们知道在哪里更改它。
您的应用可以让用户上传自己的个人资料图片并回退到 Gravatar。
如果您只是尝试从 Facebook 或 Google+ 中提取图片,这可能会吓坏您的用户,而且他们也更难知道您的服务从何处获取个人资料图片。
在PHP中使用Gravatar就这么简单:
<?php
$email = "email@server.com";
$default = ""; // absolute url to default image goes here or leave empty for default gravatar image
$size = 200;
$grav_url = "http://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?d=" . urlencode($default) . "&s=" . $size;
header("content-type: image/jpeg");
echo file_get_contents($grav_url);
?>
除此之外,您还可以使用 Facebook and/or Google+ 作为外部登录提供程序,用户可以在其中授予您的应用程序访问其个人资料信息的权限。
您应该需要访问令牌以及用户的 Facebook id。在不知道他们的情况下无法获取他们的个人资料照片
我认为 Spokeo 可能与 Facebook 达成了访问数据的协议?我不会感到惊讶。
无论如何,如果您在个人资料中,您可以在 HTML 中搜索 profile_id
。这是一个 hack,不确定它是否有效。
您始终可以允许人们通过使用他们的 g+/facebook/whatever 帐户登录来发表评论(不过需要您做一些类似 OpenID 的事情);如果他们已经登录,您应该能够获得 facebook uid。
此外,还有一个叫做 libravatar 的东西,它允许人们将图片与他们的 OpenID 或 电子邮件地址相关联(如果他们没有,它会回退到 gravatar专门为 libravatar 配置了任何东西);使用它应该会给你更多的照片,而不是你坚持使用 "just" gravatar。