首页 文章

检索仅包含电子邮件地址的Facebook / Google / Linkedin Profiles 照片

提问于
浏览
33

我需要什么

我需要自动查找和下载 Profiles 图片,以便用户只知道他的电子邮件地址 . 最初,考虑到积极使用它的人数,我专注于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 和/或 Gravatar 就可以了 .


我的第一次(原创)尝试:

一旦你有Facebook 's username or user ID, it'易于 Build URL下载图片 . 所以我试图使用带有 /search Graph 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."结束
Using 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}}

其他信息

既然's asking for 2881968 , I'也试图去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在这里似乎有点无望 .

5 回答

  • 8

    这正是为什么Gravatar存在以及为什么人们使用Gravatar,用户知道哪些公共配置文件图像绑定到哪个电子邮件地址,他们知道在哪里更改它 .

    您的应用可以让用户上传自己的 Profiles 图片并回退到Gravatar .

    如果您只是尝试从Facebook或Google中提取图像,它可能会让您的用户感到不安,而且他们也很难知道您的服务从哪里获得了 Profiles 图片 .

    在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和/或Google作为外部登录提供商,用户可以授予您的应用程序访问其 Profiles 信息的权限 .

  • 16

    有一个错误:Can't search for user by email after July 2013 Breaking Changes已被关闭为"By Design"官方回复:

    “在2013年7月10日删除了将电子邮件地址传递到”用户“搜索类型的功能 . 此搜索类型仅返回与用户姓名(包括替代名称)匹配的结果”~JosephTuấnAnhPhan( Facebook团队)

    所以可能没有来自Graph API的直接支持 .

    我已经尝试了Graph API Explorer你可以尝试使用一些FQL(只需要选择版本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
    }
    

    reference for table user表明 WHERE 中只能使用 uidthird_party_id .

  • 0

    您应该需要访问令牌以及用户的Facebook ID . 不知道他们无法获得他们的 Profiles 照片

  • 2

    我认为Spokeo可能会与Facebook达成协议来访问数据?我不会感到惊讶 .

    无论如何,如果您在 Profiles 中,您可以在HTML中搜索 profile_id . 这是一个黑客,不确定它是否有效 .

  • 0

    您可以随时通过使用他们的g / facebook /任何帐户登录来允许人们发表评论(但要求您做类似OpenID的事情);如果他们已经登录,你应该能够获得facebook uid .

    此外,还有一个名为libravatar的东西,它允许人们将图片与他们的OpenID或电子邮件地址相关联(如果他们没有专门为libravatar配置任何内容,则会回到gravatar);使用它应该比你坚持"just" gravatar给你更多的照片 .

相关问题