如何从电子邮件中获取Facebook个人资料图片?

时间:2010-05-17 18:51:42

标签: facebook

有一个名为Xobni的outlook插件,它有一个很酷的功能,如果一个联系人有一个电子邮件地址,它将获取该联系人的个人资料图片并显示它。他们的常见问题解答说明如下:

  

Xobni向Facebook发送加密的电子邮件地址,以检索当前正在Xobni边栏中查看的人的Facebook个人资料。您自己的Facebook个人资料永远不会被Xobni更改,并且在查看其他个人资料时会严格遵守所有Facebook隐私设置。

我想复制此功能。但是,我无法确定他们正在使用哪个API调用。我假设当他们说“加密的电子邮件地址”时,这是电子邮件哈希的外行人的条款。一旦导出用户名,图形api看起来非常适合实际获取图像,但是我无法从电子邮件哈希转到配置文件ID。

5 个答案:

答案 0 :(得分:13)

您可以查询以下网址以获取用户ID(如果Facebook上存在用户ID):

https://graph.facebook.com/search?access_token=YOUR_ACCESS_TOKEN&q=EMAIL_ADDRESS_URL_ENCODED&type=user

然后<img src="https://graph.facebook.com/USER_ID/picture">为您提供图片。

更多信息:article at codinglogs.com

答案 1 :(得分:3)

我正在寻找一种方法来做这件事......没有尝试过。

<击>

有没有人能够找到解决方案?

更新:我已经在PHP中整理了这个代码段。这只是我能够实现目标的唯一方式。我不确定Xobni是如何做到的(我确信它们对它的侵扰性较小)

<?php

/* Email to Search By */
$eml = 'user@domain.com';

/* This is where we are going to search.. */
$url = 'http://www.facebook.com/search.php?q=' . urlencode($eml);

/* Fetch using cURL */
$ch = curl_init();

/* Set cURL Options */
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

/* Tell Facebook that we are using a valid browser */
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13');

/* Execute cURL, get Response */
$response = curl_exec($ch);

/* Check HTTP Code */
$response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

/* Close cURL */
curl_close($ch);

/* 200 Response! */
if ($response_code == 200) {

    /* Parse HTML Response */
    $dom = new DOMDocument();
    @$dom->loadHTML($response);

    /* What we are looking for */
    $match = 'http://www.facebook.com/profile.php?id=';

    /* Facebook UIDs */
    $uids = array();

    /* Find all Anchors */
    $anchors = $dom->getElementsByTagName('a');
    foreach ($anchors as $anchor) {
        $href = $anchor->getAttribute('href');
        if (stristr($href, $match) !== false) {
            $uids[] = str_replace($match, '', $href);
        }
    }

    /* Found Facebook Users */
    if (!empty($uids)) {

        /* Return Unique UIDs */
        $uids = array_unique($uids);

        /* Show Results */
        foreach ($uids as $uid) {

            /* Profile Picture */
            echo '<img src="http://graph.facebook.com/' . $uid. '/picture" alt="' . $uid . '" />';

        }

    }

}


?

答案 2 :(得分:3)

不再可能通过Facebook Graph API使用电子邮件地址搜索用户信息。虽然如果您拥有Facebook用户ID仍然有效,但如果您无法使用搜索API获取Facebook ID,则无法再执行此操作。

https://developers.facebook.com/x/bugs/453298034751100/

API将返回以下响应:

[
{
"file_name":"150412-001070",
"date_time":"2015-07-21T13:11:55.000Z",
"polpospercent":68.95,"polnegpercent":31.05,
"Anger":6.58,
"Surprise":32.87,
"Sadness":32.87,
"Joy":4.59,
"Disgust":13.84,
"Fear":9.26,
"file_ts":"2014-04-26T22:03:00.000Z"
},

{"file_name":"150412-001070",
"date_time":"2015-07-21T13:11:55.000Z",
"polpospercent":68.95,"polnegpercent":31.05,
"Anger":6.58,
"Surprise":32.87,
"Sadness":32.87,
"Joy":4.59,
"Disgust":13.84,
"Fear":9.26,
"file_ts":"2014-05-26T22:03:00.000Z"
}
]

答案 3 :(得分:2)

非常感谢@McHerbie,你给我的线索最终让我的代码正常工作。关键是编码电子邮件的urlencode()功能!谢谢,这是我使用PHP Simple HTML Dom Parser的工作代码:

public function getFacebookPictureByScrapping($email="your@email.com", $file="fbPicture.jpg") {
            require_once('protected/extensions/simplehtmldom/simple_html_dom.php');
            $userEmail = urlencode($email);

            ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13');

            $url = "http://www.facebook.com/search.php?q=$userEmail&type=all&init=srp";
            $html = new simple_html_dom();
            $html = file_get_html($url);

            if (is_object($picture = $html->find(".uiList .img",0))) {
                $image = file_get_contents($picture->src, false);
                file_put_contents($file);
                return $file;
            } else {
                return null;
            }
    }

答案 4 :(得分:1)

我知道这篇文章有点陈旧,但只是刚刚发现它 - 你可能会尝试FullContact Person API(完全披露 - 我有偏见,我为他们工作):

http://www.fullcontact.com/developer/

一方面,当您基于电子邮件进行查询时,它将提取关联的社交媒体配置文件,以便您可以查找和提取相关的配置文件...但另一方面,您还可以节省一些时间和时间。用它直接拉动轮廓图像。

响应模式包括:

    "photos": 
  [
    {
      "typeId": [photo type],
      "typeName": [photo type name],
      "url": [photo url],
      "isPrimary": [boolean]
    }
  ]

更多信息:http://www.fullcontact.com/developer/docs/person/#lookup-by-email-3