显示随机性别(性别)朋友的个人资料使用FQL
问题描述:
if($user_gender == "male")
{
$fql_query_result = file_get_contents("https://graph.facebook.com/fql?q=SELECT+uid%2C+name+FROM+user+where+uid+IN+(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20=%20me())%20and%20sex='female'ORDER%20BY%20rand%20()%20LIMIT%201&access_token=".$access_token);
}
else
{
$fql_query_result = file_get_contents("https://graph.facebook.com/fql?q=SELECT+uid%2C+name+FROM+user+where+uid+IN+(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20=%20me())%20and%20sex='male'ORDER%20BY%20rand%20()%20LIMIT%201&access_token=".$access_token);
}
在图形API浏览器画面的显示显示随机性别(性别)朋友的个人资料使用FQL
{
"data": [
{
"uid": 100001242402868,
"name": "Don Omer"
}
]
}
如何从上面的数据中提取UID,这样我们可以显示他/她的个人资料图片
$friend_pic = imagecreatefromjpeg("http://graph.facebook.com/".$fql_query_result['uid']."/picture?type=normal");
我正在尝试创建一个名为“Who Will Marry Me”的应用程序。
在此先感谢
答
你可以做到这一切在一个查询(和一个API调用)。试试这个:
$query = 'SELECT uid, name, sex, pic FROM user WHERE
uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
AND NOT (sex IN (SELECT sex FROM user WHERE uid = me()))
ORDER BY rand() LIMIT 1';
的快速和肮脏的方法是做到:
$url = "https://graph.facebook.com/fql?q=" . urlencode($query) .
"&access_token=" . $access_token;
$spouse = json_decode(file_get_contents ($url));
printf('<p>You should marry %s. <img src="%s" /></p>',
$spouse->data[0]->name,
$spouse->data[0]->pic
);
但你真的应该使用PHP SDK,因为它是更强大。
复制/继续[显示男性用户(异性)女性朋友的个人资料图片]](http://facebook.*.com/questions/12166598/display-profile-pic-of-female-friend-for -male-user-opposite-sex) – CBroe
我删除了我以前的问题... –
你的问题是什么?你为什么不使用SDK? – Igy