如何从Facebook中吸引用户的朋友(v 2.0 Facebook Auth) [英] How to pull a user's friends from Facebook (with v 2.0 Facebook Auth)

查看:191
本文介绍了如何从Facebook中吸引用户的朋友(v 2.0 Facebook Auth)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

截至新的Facebook公告,现在,当/ me / user_friends命令拉扯朋友时,Facebook只会吸引那些已经验证了您的应用程序的朋友。如果登录的用户已经允许应用程序下载它们,是否有一种方法可以将所有用户的朋友从Facebook中拉出?



我有user_friends在我的范围内,我正在使用Laravel的madewithloveOauth2包。我也使用FB API。



目前,朋友的相关代码如下所示:

  public函数action_session($ provider,$ id = null){

// get facebook sdk
$ this-> facebook = $ this-> getFacebook($ provider);

//获取facebook auth
$ this-> auth = $ this-> getFacebookAuth();

if($ this-> auth){
return $ this-> auth;
}

//获取Facebook访问令牌
$ this-> accessToken = $ this-> getAccessToken();

//设置Facebook访问令牌
$ this-> facebook-> accessToken = $ this-> accessToken;

if(!session_id()){
session_start();
}

$ _SESSION ['fb_access_token'] = $ this-> accessToken;


$ data ['friends'] = $ this-> getFriends();

public function getFriends(){
$ results = $ this-> facebook-> get('me','friends');
return isset($ results ['data'])? $ results ['data']:array();
}

然而,这是使用Facebook所做的/ me调用,正在使用我的应用程序的人将会出现。我想要所有的用户的朋友。



在madewithlove包的provider文件夹中的Facebook.php文件中,我有(只是相关的代码):


$ b $ public $ scope = array('email','read_stream','basic_info','user_birthday','user_hometown','user_interests','user_likes','user_location' );

public function get_user_info($ token)
{
$ url ='https://graph.facebook.com/me?'.http_build_query(array(
'access_token'=> $ token-> access_token,
));

$ user = json_decode(file_get_contents($ url));

//从请求中创建一个响应
return array(
'uid'=> $ user-> id,
'first_name'=> isset($ user-> first_name)?$ user-> first_name:'',
'last_name'=> isset($ user-> last_name)?$ user-> last_name:''
'email'=> isset($ user-> email)?$ user-> email:'',
'description'=> isset($ user-> bio)? $ user-> bio:'',
'birthday'=> isset($ user-> birthday)?$ user-> birthday:'',
'gender'=> isset($ user-> gender)?$ user-> gender:'',
'location'=> isset($ user-> location-> name)?$ user-> location - > name:'',
'likes'=>'https://graph.facebook.com/me/likes?fields=category,name,id&access_token='.$token-> access_token,
'friends'=>'https:// graph .facebook.com / me / friends?fields = id,name& access_token ='。$ token-> access_token,
'image'=> 'https://graph.facebook.com/me/picture?width=720&height=720&access_token='.$token->access_token,
'urls'=>数组(
'Facebook'=> $ user->链接,
),
);
}

我的问题如何让用户在允许我时获取直接的数据访问他们的朋友列表(当他们授权应用程序),所以我可以得到所有的朋友,无论他们是否在应用程序?谢谢。

解决方案

请参阅我的答案使用Facebook API检索完整的朋友列表



请使用搜索功能StackOverflow先发布问题下一次。谢谢!


As of the new Facebook announcement, now when pulling friends with the /me/user_friends command, Facebook only pulls those friends that have also authenticated your app. Is there a way to pull all of a user's friends form Facebook anymore, if the logged in user has given permission to the App to download them?

I have "user_friends" in my scope and I am using the "madewithlove" Oauth2 package for Laravel. I am also using the FB API.

Currently the relevant code for friends looks like this:

public function action_session($provider, $id = null) {

        //get facebook sdk
        $this->facebook = $this->getFacebook($provider);

        //get facebook auth
        $this->auth = $this->getFacebookAuth();

        if($this->auth) {
            return $this->auth;
        }

        //get facebook access token
        $this->accessToken = $this->getAccessToken();

        //set facebook access token
        $this->facebook->accessToken = $this->accessToken;

        if(!session_id()) {
            session_start();
        }

        $_SESSION['fb_access_token'] = $this->accessToken;


$data['friends'] = $this->getFriends();  

public function getFriends() {
        $results = $this->facebook->get('me', 'friends');
        return isset($results['data']) ? $results['data'] : array();
    }

However, this is using the /me call which Facebook has made so that only people that are using my app will show up in. I want all of a user's friends.

In the Facebook.php file in the provider folder of the madewithlove package, I have (just the relevant code):

public $scope = array('email', 'read_stream', 'basic_info', 'user_birthday', 'user_hometown', 'user_interests', 'user_likes', 'user_location');

public function get_user_info($token)
    {
        $url = 'https://graph.facebook.com/me?'.http_build_query(array(
            'access_token' => $token->access_token,
        ));

        $user = json_decode(file_get_contents($url));

        // Create a response from the request
        return array(
            'uid' => $user->id,
            'first_name' => isset($user->first_name) ? $user->first_name : '',
            'last_name' => isset($user->last_name) ? $user->last_name : '',
            'email' => isset($user->email) ? $user->email : '',
            'description' => isset($user->bio) ? $user->bio : '',
            'birthday' => isset($user->birthday) ? $user->birthday : '',
            'gender' => isset($user->gender) ? $user->gender : '',
            'location' => isset($user->location->name) ? $user->location->name : '',
            'likes'   => 'https://graph.facebook.com/me/likes?fields=category,name,id&access_token='.$token->access_token,
            'friends' => 'https://graph.facebook.com/me/friends?fields=id,name&access_token='.$token->access_token,
            'image' => 'https://graph.facebook.com/me/picture?width=720&height=720&access_token='.$token->access_token,
            'urls' => array(
            'Facebook' => $user->link,
            ),
        );
    }

My question how do I get the direct data for the user when they allow me to access their friends list (when they Authorize the App) so I can get all of their friends, whether they are on the app or not? Thank you.

解决方案

See my answer on retrieve full list of friends using facebook API

Please use the search functionality of StackOverflow before posting a question first the next time. Thanks!

这篇关于如何从Facebook中吸引用户的朋友(v 2.0 Facebook Auth)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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