gpt4 book ai didi

python - 在 python 中制作 facebook 墙贴

转载 作者:太空狗 更新时间:2023-10-30 01:46:45 27 4
gpt4 key购买 nike

我想在我的 Facebook 粉丝专页上制作一个简单的墙报。我有我的 APP_ID + APP SECRET,我能够获得访问 token ,但我正在努力使用 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

当我运行脚本时,出现此错误:

Traceback (most recent call last):
File "fb.py", line 27, in <module>
facebook_graph = facebook.GraphAPI(oauth_response.split('=')[1])
AttributeError: 'module' object has no attribute 'GraphAPI'

我在 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'

最佳答案

PyPI 上的 Facebook 包乱七八糟。这不是 facebook你想要的,但是facebook-sdk .

确保你有正确的:

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

关于python - 在 python 中制作 facebook 墙贴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18857028/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com