【问题标题】:Get page feed with Facebook API Graph in Python在 Python 中使用 Facebook API Graph 获取页面提要
【发布时间】:2017-04-26 09:09:05
【问题描述】:

我正在尝试获取 Facebook 页面信息和提要/帖子,特别是每个帖子的文本。 我在 Facebook for Developers 上注册了一个新的测试应用程序,我得到了客户端令牌、秘密令牌和 ID。我没有插入任何隐私链接或使用条款链接,因为这是个人测试。 在 Graph API Explorer 中,我获得了应用访问令牌,并且正在使用它。 使用 facebook-sdk 我可以通过以下代码获取页面信息:

accessToken = "xxx"
user = 'BillGates'

graph = facebook.GraphAPI(accessToken, version='2.7')

profile = graph.get_object(id=user, fields='id,name,about,link,location,hometown,website', limit=100)

到目前为止,没问题。现在,我想使用以下代码获取帖子:

posts = graph.get_connections(profile['id'], connection_name='posts', fields='caption,created_time,description,from,link,message,object_id,parent_id,permalink_url,picture,privacy,place,properties,shares,source,status_type,story,to,type,with_tags', limit='100')

或在此网址创建request.get()

url = "https://graph.facebook.com/v2.7/BillGates?fields=feed{caption,created_time,description,from,link,message,object_id,parent_id,permalink_url,picture,source,status_type,type}&limit=100&access_token=xxx"

但我收到此错误:

facebook.GraphAPIError: (#15) Requires session when calling from a desktop app

我的应用程序有联系电子邮件,是本机或计算机应用程序(它将在 linux 服务器上运行),是公开的,并且只有电子邮件、public_profile 和 user_friend 作为批准的元素。其他元素无法通过,因为我要填写笔记,但是我无法填写。

我的想法是定期为我要分析的每个页面请求一个“通用”访问令牌或访问令牌。

任何帮助将不胜感激。

【问题讨论】:

  • 仅供参考:“本机或桌面应用程序”设置适用于需要在客户端代码中嵌入应用程序密码的应用程序。如果您的服务器上正在运行应用程序,则不应将其设置为是。
  • 已解决将“本机或桌面应用程序”设置为否的问题。谢谢:D

标签: python facebook api facebook-graph-api request


【解决方案1】:

这个问题已经通过使用 {client_access_token} 作为 access_token 解决了

url = "https://graph.facebook.com/v2.3/#{fb_id}/apprequests/?access_token=#{client_access_token}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多