[英]How do I get friends gender using facebook api and fql
I am new to PHP and FQL. 我是PHP和FQL的新手。 I know how it needs to be done, but don't know the codes.
我知道它需要怎么做,但不知道代码。 Creating an application where user sees only the opposite gender in box.
创建一个用户只能在框中看到异性的应用程序。
I got up to getting the the user's name, gender and friends id. 我起身得到用户的姓名,性别和朋友ID。 Now I need help running the FQL to and getting the gender of all the friends and insert the names of the opposite gender in .
现在我需要帮助运行FQL并获取所有朋友的性别并插入异性的名称。
<?php
$fbuser = $facebook->api('/me');//getting users data
$friends = $facebook->api('/me/friends'); //getting friends data (only gives id and name)
$userName = $fbuser['name'];//getting users name
$userGender = $fbuser['gender'];//getting users gender
$friendsId = array();//empyt array to insert friends id
foreach ($friends['data'] as $value);{ //loop
array_push($friendsId, $value['id']); // not sure if this correct
$friendsGender = friendsGender ;//run FQL to get the friends gender using the id
//conditional Statement, if users and friends gender is not same insert the friends name in <select>
?>
I did the following but it didn't work. 我做了以下但是没有用。 Is my second line of script correct?
我的第二行脚本是否正确?
$friendsInfo = $facebook->api('/me/friends', array('fields' => 'id,name,gender'));
$friendsGender = $friendsInfo['gender'];
echo $friendsGender;
You can get a friend's data by: 您可以通过以下方式获取朋友的数据:
foreach ($friends['data'] as $value){
$friend = $facebook->api('/'+$value['id']);
But that's very inefficient. 但那效率很低。 Luckily there's another solution - you can specify which fields you want facebook to return:
幸运的是还有另一种解决方案 - 您可以指定您希望Facebook返回的字段:
$facebook->api('/me/friends', array('fields' => 'id,name,gender'));
PS. PS。 it's graph api calls;
它是图形api调用; fql is something else
fql是别的东西
PPS. PPS。
foreach ($friends['data'] as $value);{
is buggy - the block is outside/after the loop foreach ($friends['data'] as $value);{
is buggy - 块在循环之外/之后
You may try something like: 您可以尝试以下方法:
<?php
$access_token = 'AABBCC...';
$param = array(
'access_token' => $access_token,
'method' => 'GET',
'q' => 'SELECT name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())'
);
$fql = 'https://graph.facebook.com/fql?' . http_build_query($param);
$res = file_get_contents($fql);
$aRes = json_decode($res, 1);
You can even choose to filter adding WHERE sex = "female" AND uid IN (..)
to your query 您甚至可以选择过滤将
WHERE sex = "female" AND uid IN (..)
到您的查询中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.