2011-11-22 101 views
1

我正在尝试使用Graph API访问用户的朋友工作和教育历史记录。我在auth对话中包含了两个权限。我尝试使用FQL访问它们,但没有运气。使用FB Graph API获取用户朋友数据

try{ 
     $fql = "select friends_education_history from permissions where uid=" . $user; 
     $param = array(
      'method' => 'fql.query', 
      'query'  => $fql, 
      'callback' => '' 
     ); 
     $fqlResult = $facebook->api($param); 
    } 
    catch(Exception $o){ 
     d($o); 
    } 
} 

我宁愿不使用FQL访问信息,但在这一点上,我需要弄清楚任何方式。有没有办法做这样的事情:

if($user_id) { 
    try { 
     $friends = $facebook->api("/me/friends"); 
    } 
    catch(Exception $o){ 
     d($o); 
    } 
} 
?> 

然后调用各自的变量?

回答

0

你FQL查询会是这个样子:

SELECT education,work from user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) 

上面的查询将从登录用户的朋友获取所有的教育和工作对象。

SELECT education,work from user WHERE uid = <YOUR FRIENDS USER ID> 

上面的查询会得到教育和工作仅仅是一个用户ID您提供

希望这有助于!

+0

非常感谢。现在很好走。 – buttonitup

+0

马特,如果您可以将它标记为答案,如果它适合您,那将是非常好的。谢谢,祝你好运! – TheV

+0

@buttonitup为你做了这项工作? – emersonthis

0

User graph api object有字段educationwork

权限user_education_history & friends_education_history需要用于第一,user_work_history & friends_work_history用于第二。

这些字段是可选的&用户可以通过她的个人资料页限制其可见性,因此即使授予了权限,api也可能不会返回任何内容。使用Graph api explorer玩。

+0

我有这个完全相同的问题。我向用户请求了正确的权限,但是如果我从'/ me/friends?fields = work,education'切换到'/#user_id#/ friends?fields = work,education,则API不会返回这些字段'。 – emersonthis

相关问题