我可以通过个人资料URL或用户名获取任何用户的Facebook ID吗? [英] Can I get Facebook Id of any user through Profile URL or Username?

查看:78
本文介绍了我可以通过个人资料URL或用户名获取任何用户的Facebook ID吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有任何Facebook用户使用其个人资料网址或用户名,我该如何获取用户.

How can I get user if of any facebook user using its profile url or its username.

我想实现与本网站中所示的功能相同.

I want to implement the same functionality as shown in this website.

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

I have tried using https://graph.facebook.com/username but it gives me the following error

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

我还看到了这篇文章和它说Facebook不允许从用户名获取ID.如果为真,那么此网站如何获取ID

I have also seen this post and it says that facebook does not allow getting an id from the username.If it's true then how does this website gets the id

推荐答案

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

you try old method ...for new you need facebook access token

并尝试这种类型-

$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'];

这篇关于我可以通过个人资料URL或用户名获取任何用户的Facebook ID吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆