我想在我的facebook粉丝页面上做一个简单的留言。我有我的APP_ID+APP SECRET,我可以获得访问令牌,但我正在努力facebook.GraphAPI网站() 代码如下:
# -*- coding: utf-8 -*-
import urllib
import facebook
FACEBOOK_APP_ID = '12345'
FACEBOOK_APP_SECRET = '123456789'
FACEBOOK_PROFILE_ID = '321321321321'
oauth_args = dict(
client_id = FACEBOOK_APP_ID,
client_secret = FACEBOOK_APP_SECRET,
grant_type = 'client_credentials')
oauth_response = urllib.urlopen('https://graph.facebook.com/oauth/access_token?'
+ urllib.urlencode(oauth_args)).read()
# oauth_response looks like this:
# access_token=2732467743847839726|3gddzdg3Wl-5S_Go
attach = {
"name": 'Hello',
"link": 'http://www.link.com',
"caption": 'test',
"description": 'some test',
"picture" : 'http://img/picture.png',
}
facebook_graph = facebook.GraphAPI(oauth_response.split('=')[1])
try:
response = facebook_graph.put_wall_post('', attachment=attach)
except facebook.GraphAPIError as e:
print e
运行脚本时,出现以下错误:
^{pr2}$我在windows和ubuntu机器上尝试了这个代码,同样的错误。我试着重新安装facebook模块,但没有任何帮助。有人知道如何解决这个问题吗?在
编辑:
当我添加import pydoc; pydoc.help(facebook)
时,这是输出:
Help on package facebook:
NAME
facebook - TODO: Document your package.
FILE
c:\python26\lib\site-packages\facebook-0.0-py2.6.egg\facebook\__init__.py
PACKAGE CONTENTS
DATA
__loader__ = <zipimporter object "C:\Python26\lib\site-packages\facebo...
__version__ = 'TODO: Enter a version'
VERSION
TODO: Enter a version
Traceback (most recent call last):
File "fb.py", line 29, in <module>
facebook_graph = facebook.GraphAPI(oauth_response.split('=')[1])
AttributeError: 'module' object has no attribute 'GraphAPI'
那个包裹不对。请尝试从this github repo重新下载和安装。在
我也做了同样的操作,这是我从
pydoc.help(facebook)
(在交互提示下也是help
)的输出:所以没有正确安装。在
我建议将
facebook.py
文件复制到当前目录(与问题中的文件相同)并重新运行。希望你能绕过这个拙劣的安装。在PyPI上的Facebook包一团糟。你想要的不是^{} ,而是^{} 。在
确保您有正确的选择:
相关问题 更多 >
编程相关推荐