are*_*ddy -1 python facebook facebook-graph-api facebook-sdk-4.0
我通过控制台在python中安装了facebook模块
pip install facebook-sdk
Run Code Online (Sandbox Code Playgroud)
然后注册到facebook api获取app_id和app_secret.I我没有在下面透露它们.
import facebook
app_id = '00000'
app_secret = 'xxxx'
access_token = facebook.get_app_access_token(app_id,app_secret)
Run Code Online (Sandbox Code Playgroud)
当我执行它来获取access_token时,我的python控制台抛出以下错误:
Traceback (most recent call last):
File "<ipython-input-18-0dfc0fd92367>", line 1, in <module>
access_token = facebook.get_app_access_token(app_id,app_secret)
AttributeError: 'module' object has no attribute 'get_app_access_token'
Run Code Online (Sandbox Code Playgroud)
请帮忙.
这是一个已知问题.只需卸载facebook和facebook-sdk然后只能重装facebook-sdk.
sudo pip uninstall facebook
sudo pip uninstall facebook-sdk
sudo pip install facebook-sdk
Run Code Online (Sandbox Code Playgroud)
此外,您可以实现自己get_app_access_token的:
def get_app_access_token(app_id, app_secret):
"""Get the access_token for the app.
This token can be used for insights and creating test users.
@arg app_id :type string :desc retrieved from the developer page
@arg app_secret :type string :desc retrieved from the developer page
Returns the application access_token.
"""
# Get an app access token
args = {'grant_type': 'client_credentials',
'client_id': app_id,
'client_secret': app_secret}
f = urllib2.urlopen("https://graph.facebook.com/oauth/access_token?" +
urllib.urlencode(args))
try:
result = f.read().split("=")[1]
finally:
f.close()
return result
Run Code Online (Sandbox Code Playgroud)
结果将包含您的访问令牌.
| 归档时间: |
|
| 查看次数: |
1306 次 |
| 最近记录: |