我正在尝试使用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')
第二,但我对如何这样做没有任何线索。
我是否必须进行两次单独的查询?
答案 0 :(得分:1)
python facebook-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))
答案 1 :(得分:0)
我稍微修改了你的查询。你可以试试here。如果没有,请单击“获取访问令牌”。
{
"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"
}
此外,您真的不必进行多次查询。你可以使用这个(test it):
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
要从您的应用发出请求,您应该正确编码数据。例如,对于这两个查询网址都是:
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