使用python的Facebook查询语言

2024-04-18 17:05:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我在https://developers.facebook.com/tools/explorer?fql=中使用了以下查询

SELECT aid FROM album WHERE owner = "100001741044617";

我得到了正确的输出。在

我尝试通过python使用相同的查询并提取出我遇到问题的输出。 我正在发布python代码和输出

代码:

^{pr2}$

输出

[root@IN-AIR-BIMAPP106 ~]# python /opt/fql.py 
SELECT aid FROM album WHERE owner = "100001741044617"
SELECT%20aid%20FROM%20album%20WHERE%20owner%20%3D%20%22100001741044617%22
{"error":{"message":"A user access token is required to request this resource.","type":"OAuthException","code":102}}

我已经生成了所需的访问令牌用户照片。 请告诉我该怎么办。谢谢。在


Tags: 代码fromhttpscomalbumfacebookwheretools
1条回答
网友
1楼 · 发布于 2024-04-18 17:05:34

访问令牌需要包含在查询中。例如,要获得所有朋友:

query = "SELECT uid2 FROM friend WHERE uid1 = me()"
params = urllib.urlencode({'q': query, 'access_token': YOUR_ACCESS_TOKEN})
print params

'q=SELECT+uid2+FROM+friend+WHERE+uid1+%3D+me%28%29&access_token=YOUR_ACCESS_TOKEN'

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

'{"data":[{"uid2":"#######"},{"uid2":"#######"},{"uid2":"#######"}, ...

相关问题 更多 >