本文介绍了如何在Facebook图表api中过滤男女身份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何通过

<?php
 //get the user gender 
        $user_id = $facebook->getUser();
        $user_profile = $facebook->api('/me','GET');
        $user_gender = $user_profile['gender'];
        echo "Gender: " . $user_gender;
?>

但我需要获得10个女性ID或10个男性ID ..(不混合)想要请吗?

but I need to get any 10 female ID or 10 Male ID ..(Not Mixed).Any Ideas Please?

ps:我不想要fql请

ps: i don't want fql please

推荐答案

p>你的问题不是很清楚,你从哪里尝试获取用户ID。
我假设你要分开你的朋友的ids
首先检索好友列表:

Well your question is not very clear about from where your are trying the get user ids. I am assuming that you want to seperate ids of your friends.First retrieve friend list:

$f=$facebook->api('/me/friends',array('access_token'=>$accessToken));

然后定义两个数组: male = new array(); female = new array(); 。循环检查每个朋友的性别:

Then define two arrays: male=new array(); and female=new array(); . Loop to check gender of each friend:

foreach($f as $t){
   $usr=$facebook-api("/$t['id']");
       if($usr['gender']=='male')
           $male[]=$usr['id'];
       else 
           $female[]=$usr['id']; 
}

在循环结束时,您将拥有所有男性和女性在各自的阵列中。

At the end of the loop you will have all males and females in their respective array.

这篇关于如何在Facebook图表api中过滤男女身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 00:44