2015-03-31 61 views
0

我想通过使用HWIOauthBundle访问oauth后由facebook发送的user_friends。HWIOauth&Facebook访问user_friends

##config.yml 
    resource_owners: 
      facebook: 
       type:    facebook 
       client_id:   %facebook_app_id% 
       client_secret:  %facebook_app_secret% 
       scope:    "email, public_profile, user_friends" 
       infos_url:  "https://graph.facebook.com/me?fields=id,name,email,picture.type(square)" 
       paths: 
        email:   email 
        profilepicture: picture.data.url 

loadUserByOAuthUserResponse(UserResponseInterface $response)

我这样做记录的数据:

$attr = $response->getResponse(); 
$this->logger->info(print_r($attr,true)); 

,我得到的输出数组的信息:

Array 
(
    [id] => 1015539########## 
    [name] => john smith 
    [email] => [email protected] 
    [picture] => Array 
     (
      [data] => Array 
       (
        [is_silhouette] => 
        [url] => https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/v/t1.0-1/p50x50/10998###_1015530##########_207119375##########_n.jpg?oh=1f0e94af68daa############f888611&oe=5#######&__gda__=1###720385_a2c0bb15f160abf4############3289 
       ) 
     ) 
) 

(# ###和为隐私添加的假名称)

如何访问user_friends?

我相信它正在开发Facebook的结束,因为它会要求得到允许在登录时。

+0

现在你只能得到同样使用相同应用程序的用户的朋友。 – zerkms 2015-03-31 06:52:17

+0

是的,我知道。我仍然喜欢这个数据。有多个用户共享应用程序 – Chris 2015-03-31 12:49:39

回答

1

你是在正确的轨道上。您在登录用户时获得了user_friends权限。

下一步是对/ me/friends边缘(使用该人当前获得的访问令牌)进行Graph API调用并解析响应。

我不知道,如果你有Facebook的SDK集成到您的PHP应用程序,但如果是这样,你需要做的是:

/* PHP SDK v4.0.0 */ 
/* make the API call */ 
$request = new FacebookRequest(
    $session, 
    'GET', 
    '/me/friends' 
); 
$response = $request->execute(); 
$graphObject = $response->getGraphObject(); 
/* handle the result */ 

或者你可以做一个卷曲的呼叫。有关如何做此项检查https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends

+0

谢谢。 Facebook SDK就是答案。 – Chris 2015-04-07 23:05:06

1

我已经在我的config.yml添加完成它的更多信息:

resource_owners: 
    facebook: 
     type:    facebook 
     client_id:   "%fb_app_id%" 
     client_secret:  "%fb_app_secret%" 
     scope:    "email,user_friends" 
     infos_url:   "https://graph.facebook.com/me?fields=id,name,email,picture.type(square),friends" 
     options: 
      display: page 
     paths: 
      friends: friends 
      profilepicture: picture.data.url 

现在在FOSUBUserProvider的loadUserByOAuthUserResponse你可以从响应好友资料。 SDK是不必要的。