【问题标题】:Can I get Facebook Id of any user through Profile URL or Username?我可以通过个人资料 URL 或用户名获取任何用户的 Facebook ID 吗?
【发布时间】:2018-04-04 05:59:04
【问题描述】:

如果任何 facebook 用户使用其个人资料 url 或用户名,我如何获取用户。

我想实现与this website 中所示相同的功能。

我尝试过使用https://graph.facebook.com/username,但它给了我以下错误

{
   "error": {
      "message": "(#803) Cannot query users by their username (username)",
      "type": "OAuthException",
      "code": 803,
      "fbtrace_id": "G8AjtLUd3AC"
   }
}

我也见过this post,它说facebook不允许从用户名获取id。如果是真的那么this website如何获取id

【问题讨论】:

  • “那么这个网站是如何获取id的” - 通过抓取,这是不允许的。 “我想实现与 [...] 相同的功能” - 为什么?它甚至没有任何实际用途,你不能对用户的全局 ID 做很多事情。

标签: html facebook facebook-graph-api


【解决方案1】:

您尝试旧方法...对于新方法,您需要 facebook 访问令牌

试试这种类型-

$access_token = "EAAAAAYsX7TsBAH1efzbZAhqJREQfwzZCNIZBgGVbpxoLaoZBOVx4KminpzqkiczMC19pVdjqX6fVj3jIxxdGaROSyr04ZCYmhSe59UMZAwZAKH5YJ7dnawHwgYSLvbJa4TV8kqAkO6l5mcgVIVfeE6trgm7hh01RJ7SB0hDc7scQ8YineE0exabZCmuYOvnldngEopPEYBZAZBVCZC4knDHGNZCKwk0fj36526MZD";


function getFacebookIdFromUrlandUsername($url,$access_token) {
/**
 * Taken from https://www.allautoliker.com/find_id, the valid formats are:
 * dr.p.pareek
 * https://www.facebook.com/leloweb
 * https://m.facebook.com/dr.p.pareek
 * https://www.facebook.com/profile.php?id=100001148755604
 */
$correctURLPattern = '/^https?:\/\/(?:www|m)\.facebook.com\/(?:profile\.php\?id=)?([a-zA-Z0-9\.]+)$/';
if (!preg_match($correctURLPattern, $url, $matches)) {
    $getinf = 'https://graph.facebook.com/' .$url.'/?access_token='.$access_token;
    $info = json_decode(file_get_contents($getinf), true);
    return $info;
}else{
    $getinf = 'https://graph.facebook.com/' .$matches[1].'/?access_token='.$access_token;
    $info = json_decode(file_get_contents($getinf), true);
    return $info;
}
}
$find_id = "dr.p.pareek";
$user = getFacebookIdFromUrlandUsername($find_id,$access_token);
 //echo '<pre>';
//print_r($user);

echo $user['id'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多