0

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

SELECT aid FROM album WHERE owner = "100001741044617";

我得到了正确的输出。

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

代码:

import urllib
query = "SELECT aid FROM album WHERE owner = \"100001741044617\""
print(query)
query = urllib.quote(query)
print(query)
url = "https://graph.facebook.com/fql?q=" +query

data = urllib.urlopen(url).read()
print(data)

输出

[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}}

我已经生成了所需的访问令牌 user_photoes。请让我知道该怎么做。谢谢。

4

1 回答 1

1

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

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":"#######"}, ...
于 2013-05-22T08:05:21.543 回答