Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从Facebook授权用户处获取用户朋友列表?_Php_Facebook_Laravel_Facebook Friends_Laravel Socialite - Fatal编程技术网

Php 如何从Facebook授权用户处获取用户朋友列表?

Php 如何从Facebook授权用户处获取用户朋友列表?,php,facebook,laravel,facebook-friends,laravel-socialite,Php,Facebook,Laravel,Facebook Friends,Laravel Socialite,我正在研究在用户授权应用程序查看其用户朋友后,是否可以查看某个用户的朋友列表,但我没有完全理解这个想法,因此我想知道,是否有一种直接的方法可以查看列表,而无需查看图形API之类的内容? 我正在使用Laravel的社交名媛软件包登录,它似乎工作得很好,并返回默认信息(电子邮件、姓名、头像等),以及其他允许的信息,如出生日期、地点和家乡。然而,我发现很难查看照片、帖子、朋友和群组等的列表。。即使用户允许我这样做 提前多谢 你就是做不到 Facebook不允许您获取好友列表,只允许您获取已经在使用您的

我正在研究在用户授权应用程序查看其用户朋友后,是否可以查看某个用户的朋友列表,但我没有完全理解这个想法,因此我想知道,是否有一种直接的方法可以查看列表,而无需查看图形API之类的内容? 我正在使用Laravel的社交名媛软件包登录,它似乎工作得很好,并返回默认信息(电子邮件、姓名、头像等),以及其他允许的信息,如出生日期、地点和家乡。然而,我发现很难查看照片、帖子、朋友和群组等的列表。。即使用户允许我这样做


提前多谢

你就是做不到

Facebook不允许您获取好友列表,只允许您获取已经在使用您的应用程序的好友列表。在API的官方文档中,我们可以阅读:

这将只返回使用(通过Facebook登录)该应用程序发出请求的所有朋友。如果此人的朋友拒绝用户的朋友权限,该朋友将不会出现在此人的朋友列表中

更重要的是,您无法从Laravel获得使用Socialite的朋友列表,因此我建议您使用另一个Laravel软件包,例如:


干杯

以上所有信息都是正确的,除了您可以通过社交名将好友列表和更多信息添加到“控制器中的字段和范围”中之外

例如:


这个答案只是扩展并解释了如何使用@jayenne所说的来实现这一点

在redirect()函数中,可以进行如下调用:

    public function redirect() {
        return Socialite::driver('facebook')
            ->fields([
                'friends'
            ])
            ->scopes([
                'user_friends'
            ])->redirect();
    }
上面,我们要求社交名媛请求
user\u friends
权限,并将其存储到名为
friends
的字段中。现在,在您的回调中,您可以在SociateUser中获得
friends
字段,如下所示:

   public function callback(SocialFacebookAccountService $service) {
        $socialiteUser = Socialite::driver('facebook')
            ->fields(['friends'])
            ->user();

        //Loop through all the facebook friends returned (who are already on your site and friends with the recently registered user)
        foreach($socialiteUser->user['friends']['data'] as $fbFriend) {
            //do something with this facebook friend here
        }
        //Most tutorials log the user in like this; you define the $service and the method
        //You can find a tutorial in the Socialite docs/github repo
        $user = $service->createOrGetUser($socialiteUser);
        auth()->login($user);
        return redirect('/home');
   }

是的。Laravel社交名流仅用于身份验证。我切换到SammyK插件。谢谢。这是正确的,除了社交名流部分,你绝对可以从社交名流那里得到朋友名单!见下文
   public function callback(SocialFacebookAccountService $service) {
        $socialiteUser = Socialite::driver('facebook')
            ->fields(['friends'])
            ->user();

        //Loop through all the facebook friends returned (who are already on your site and friends with the recently registered user)
        foreach($socialiteUser->user['friends']['data'] as $fbFriend) {
            //do something with this facebook friend here
        }
        //Most tutorials log the user in like this; you define the $service and the method
        //You can find a tutorial in the Socialite docs/github repo
        $user = $service->createOrGetUser($socialiteUser);
        auth()->login($user);
        return redirect('/home');
   }