导入模块facebook时为什么会出现此错误?

2024-04-26 18:48:10 发布

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

#!/usr/bin/python
import facebook
import facepy
from facepy import GraphAPI


graph = facebook.GraphAPI(oauth_access_token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")

friends = graph.get_connections("me", "friends") Traceback (most recent call last): File "", line 1, in AttributeError: 'GraphAPI' object has no attribute 'get_connections'


Tags: fromimportgetfacebookbinobjectaccessusr
2条回答

PyPI上的Facebook包搞砸了。你想要的不是facebook,而是facebook sdk。你知道吗

确保你有合适的:

pip uninstall facebook  # Remove the broken package
pip install facebook-sdk  # Install the correct one

你必须在FaceBook上注册oauth_access_token:link。你知道吗

基本用法:

import facebook
graph = facebook.GraphAPI(oauth_access_token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
graph.put_object("me", "feed", message="I am writing on my wall!")

参考书目:

  1. pythonforfacebook/facebook-sdk http://goo.gl/mUuIH
  2. FB SDK Third-Party http://goo.gl/rNFyW4

相关问题 更多 >