如何在python中进行FQL查询?

时间:2011-07-26 05:48:10

标签: python facebook facebook-fql

假设用户已经使用javascript SDK进行了身份验证,您将如何在python中执行FQL查询 - >

 query = 'SELECT page_id FROM page_admin WHERE uid = ' + user_id

我已阅读文档,您似乎必须点击此网址 - >

https://api.facebook.com/method/fql.query?query=QUERY

你是怎么做到的?你还需要在网址中传递访问令牌,如果是,那么如何?

3 个答案:

答案 0 :(得分:6)

import urllib

query = "SELECT name FROM user WHERE uid = \"4\""
print(query) 

query = urllib.quote(query)
print(query) 

url = "https://graph.facebook.com/fql?q=" + query
data = urllib.urlopen(url).read()
print(data)

输出:

SELECT name FROM user WHERE uid = "4"
SELECT%20name%20FROM%20user%20WHERE%20uid%20%3D%20%224%22
{"data":[{"name":"Mark Zuckerberg"}]}

FQL reference

答案 1 :(得分:2)

https://api.facebook.com/method/fql.query?query=QUERY 用FQL替换QUERY, 例如:https://api.facebook.com/method/fql.query?query = SELECT%20aid,%20owner,%20name,%20object_id%20FROM%20album%20WHERE%20aid =%2220531316728_324257%22

答案 2 :(得分:1)

您应该使用urllib2,检查urlopen方法。

根据您正在进行的查询,您需要访问令牌,例如,如果您想要检索相册,则需要访问令牌和user_photos以及friend_photos权限,以便检索您不需要的任何粉丝页面信息