栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

以编程方式获取使用Facebook Graph API的访问令牌

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

以编程方式获取使用Facebook Graph API的访问令牌

更新2018-08-23

由于这仍然有一些意见和支持,我只想提一提,到目前为止,似乎存在一个维护良好的第三方SDK:https : //github.com/mobolic/facebook-
sdk


迟到总比不到好,也许其他人正在寻找它。我在MacBook上使用Python 2.6了。

这需要你有

  • 安装的Python facebook模块:https : //github.com/pythonforfacebook/facebook-sdk,
  • 实际的Facebook应用设置
  • 并且您要发布到的个人资料必须已授予适当的权限,以允许所有不同的内容(例如读写)。

您可以在Facebook开发人员文档中阅读有关身份验证的内容。有关详细信息,请参见https://developers.facebook.com/docs/authentication/。

这篇博客文章也可能对此有所帮助:http : //blog.theunical.com/facebook-
integration/5-steps-to-publish-on-a-facebook-wall-using-
php/

开始:

#!/usr/bin/python# coding: utf-8import facebookimport urllibimport urlparseimport subprocessimport warnings# Hide deprecation warnings. The facebook module isn't that up-to-date (facebook.GraphAPIError).warnings.filterwarnings('ignore', category=DeprecationWarning)# Parameters of your app and the id of the profile you want to mess with.FACEBOOK_APP_ID     = 'XXXXXXXXXXXXXXX'FACEBOOK_APP_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'FACEBOOK_PROFILE_ID = 'XXXXXX'# Trying to get an access token. Very awkward.oauth_args = dict(client_id     = FACEBOOK_APP_ID,       client_secret = FACEBOOK_APP_SECRET,       grant_type    = 'client_credentials')oauth_curl_cmd = ['curl',       'https://graph.facebook.com/oauth/access_token?' + urllib.urlenpre(oauth_args)]oauth_response = subprocess.Popen(oauth_curl_cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()[0]try:    oauth_access_token = urlparse.parse_qs(str(oauth_response))['access_token'][0]except KeyError:    print('Unable to grab an access token!')    exit()facebook_graph = facebook.GraphAPI(oauth_access_token)# Try to post something on the wall.try:    fb_response = facebook_graph.put_wall_post('Hello from Python',    profile_id = FACEBOOK_PROFILE_ID)    print fb_responseexcept facebook.GraphAPIError as e:    print 'Something went wrong:', e.type, e.message

对获取令牌进行错误检查可能会更好,但是您会想到要做什么。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/651649.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号