2015-01-16 35 views
3

我有在Python 2.7使用Facebook图形API访问数据下面的简单的例子(使用水蟒分布):Facebook的图形API“模块”对象没有属性“GraphAPI”

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 

最初我'module'对象没有'GraphAPI'属性,并且注意到Facebook的预填充方法列表基本上是空的。这导致我采取this post的建议并卸载facebook并安装facebook-sdk。这个工作在现在GraphAPI在预填充的列表中显示的感觉,但我仍然得到以下错误:

AttributeError: 'module' object has no attribute 'GraphAPI'

是否有另一种解决这个问题,我可能俯瞰?

回答

2

这是一个已知的问题。只需卸载facebook和facebook-sdk,然后只重新安装facebook-sdk。

GraphApi module present in pyfacebook or not

Python Facebook SDK: 'module' object has no attribute 'GraphAPI'

UPDATE1:

我想我现在弄明白了。我认为你没有使用令牌。只是试试这个:

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 
+0

嗨DevTec,我已经试过,如上所述,这是唯一可能的原因吗?我将需要首先使用git命令并尝试使用git解决方案来确保我已经用尽所有选项。 – 114

+0

看看我的编辑 – DevTec

+0

对不起,我已更新我的帖子以显示(令牌)的用法,那是我的错误。我也尝试安装git并使用第一个链接中描述的git方法,但没有运气。我想知道是否它与Anaconda没有正确卸载Facebook或类似的东西。 – 114

相关问题