0

我正在尝试使用 graph.fql 进行多查询,但我无法让它工作,而且我在文档中看不到任何示例。我正在尝试运行

'user_sex': 'SELECT sex FROM user WHERE uid=me()'

先后

'friends': 'SELECT uid, name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND NOT (sex IN #user_sex) ORDER BY name')

第二,但我不知道如何做到这一点。

我必须进行两个单独的查询吗?

4

2 回答 2

1

pythonfacebook-sdk库可以执行多个 FQL 查询。您需要先将查询字典转换为字符串。

import facebook

query = {
    "user_sex": "SELECT sex FROM user WHERE uid=me()",
    "friends": "SELECT uid, name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND not (sex in (select sex from #user_sex))  ORDER BY name"
}

graph = facebook.GraphAPI(access_token)
return graph.fql(str(query))
于 2014-04-07T03:49:09.363 回答
0

我稍微修改了您的查询。你可以在这里试试。如果没有,请单击“获取访问令牌”。

{
"user_sex": "SELECT sex FROM user WHERE uid=me()",
"friends": "SELECT uid, name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND not (sex in (select sex from #user_sex))  ORDER BY name"
}

此外,您真的不必进行多次查询。您可以使用这个(测试它):

SELECT uid,name, sex 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 name

要从您的应用程序发出请求,您应该正确编码数据。例如,对于这两个查询 url 将是:

https://graph.facebook.com/fql?q=%7B%22user_sex%22:%22SELECT%20sex%20FROM%20user%20WHERE%20uid=me()%22,%22friends%22:%22SELECT%20uid,%20name,%20sex%20FROM%20user%20WHERE%20uid%20IN%20(SELECT%20uid2%20FROM%20friend%20WHERE%20uid1%20=%20me())%20AND%20not%20(sex%20in%20(select%20sex%20from%20%23user_sex))%20%20ORDER%20BY%20name%22%7D&access_token=token
https://graph.facebook.com/fql?q=SELECT+uid,+name,+sex+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+name&access_token=token
于 2013-06-26T13:02:35.577 回答