Facebook FQL 按图形 API 中的随机替代项排序


facebook fql order by random alternative in graph api

$ret = $facebook->api( array(
'method' => 'fql.query',
'query' => "SELECT uid, name, pic_square FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1 ORDER BY rand() limit 12"
));

我使用此代码来获取 12 个随机朋友。但是当我用下面的代码替换上面的代码时

$ret = $facebookObj->getFacebookRequestResponse($facebook, "GET", "/me/friends/?fields=id,name,picture&limit=12");

我有12个朋友,但他们不是随机来的。我该如何解决这个问题?

目前无法将自定义排序参数应用于图形 API 请求 afaik。

  • https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#reading

最简单的方法是检索所有朋友并将它们分配给数组,使用 PHP 随机函数从数组中提取 X 个随机值

<?php
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
echo $input[$rand_keys[0]] . "'n";
echo $input[$rand_keys[1]] . "'n";
?>

http://php.net/manual/en/function.array-rand.php