我在 Python 2.7(使用 Anaconda 发行版)中有以下简单示例,用于使用 Facebook Graph API 访问数据:
import facebook
token = 'mytoken'
graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print friend_list
最初,我得到的“模块”对象没有属性“GraphAPI”,并注意到 facebook 的预填充方法列表基本上是空的。这促使我采纳了this post的建议。并卸载 facebook 并安装 facebook-sdk。从某种意义上说,这有效,现在 GraphAPI 显示在预填充列表中,但我仍然收到以下错误:
AttributeError:“模块”对象没有属性“GraphAPI”
对于我可能忽略的这个问题还有其他解决方案吗?
最佳答案
这是一个已知问题。只需卸载 facebook 和 facebook-sdk,然后仅重新安装 facebook-sdk。
GraphApi module present in pyfacebook or not
Python Facebook SDK: 'module' object has no attribute 'GraphAPI'
更新1:
我想我现在明白了。我认为您没有使用 token 。试试这个:
import facebook
token = 'mytoken'
graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print friend_list
关于facebook-graph-api - Facebook Graph API 'module' 对象没有属性 'GraphAPI',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27988999/