使用Unity Facebook SDK 5.0.3,我怎样才能得到N个随机朋友?

时间:2014-01-31 00:50:36

标签: random friend facebook-unity-sdk

FB.API召唤10个随机朋友会是什么意思?我很确定这可以通过fql查询完成,但我不知道确切的语法。

它将具有以下形式:

FB.API(fqlQuery,Facebook.HttpMethod.GET,getNRandomFriendsCallback);

所以我的问题是fqlQuery应该等于什么?

我目前设置为:string fqlQuery =“/ fql?q = {SELECT uid,name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me())ORDER BY rand()limit 10}” ;

但这会导致400 Bad Request。

谢谢。

1 个答案:

答案 0 :(得分:2)

你需要对你的fql查询进行url编码,因为它作为HTTPS GET参数通过网络传输:

var fqlQuery = "/fql?q=" + WWW.EscapeURL("SELECT uid, name FROM user WHERE uid IN ( SELECT uid2 FROM friend WHERE uid1 = me() ) ORDER BY rand() limit 10");
FB.API(fqlQuery, Facebook.HttpMethod.GET, getNRandomFriendsCallback);

fqlQuery将如下所示:/fql?q=SELECT%20uid%2C%20name%20FROM%20user%20WHERE%20uid%20IN%20(%20SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20%3D%20me()%20)%20ORDER%20BY%20rand()%20limit%2010

您可以在此处详细了解Unity的网址编码方法: http://docs.unity3d.com/Documentation/ScriptReference/WWW.EscapeURL.html