简体   繁体   English

使用Python中的Facebook API Graph获取页面供稿

[英]Get page feed with Facebook API Graph in Python

I'm trying to fetch facebook page information and feed/posts, and specifically the text of each post. 我正在尝试获取Facebook页面信息和提要/帖子,特别是每个帖子的文本。 I've registered a new test app, on Facebook for Developers, and I get client token, secret token and ID. 我在Facebook for Developers上注册了一个新的测试应用程序,我获得了客户端令牌,秘密令牌和ID。 I've not inserted any privacy link or Terms of Use link because it is a personal test. 我没有插入任何隐私链接或使用条款链接,因为它是个人测试。 In the Graph API Explorer I get the app access token, and I'm using it. 在Graph API Explorer中,我获得了应用访问令牌,我正在使用它。 Using facebook-sdk I can get pages information via the following code: 使用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)

So far, no problem. 到目前为止,没问题。 Now, I would want to get posts with this code: 现在,我想要获得这个代码的帖子:

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')

or making a request.get() at this url: 或在此网址上发出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"

but I receive this error: 但是我收到这个错误:

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

My app has the contact email, is a native or computer application (it will run on a linux server), is public and has just email, public_profile and user_friend as approved elements. 我的应用程序有联系电子邮件,是本机或计算机应用程序(它将在Linux服务器上运行),是公共的,只有电子邮件,public_profile和user_friend作为批准的元素。 Other elements can't be approved because I've to fill notes, but I'm unable to fill them. 其他元素不能被批准,因为我要填写笔记,但我无法填写它们。

My idea is to request, periodically, a "general" access token, or an access token for each page I've to analyze. 我的想法是定期请求“常规”访问令牌或我要分析的每个页面的访问令牌。

Any helps would be appreciated. 任何帮助将不胜感激。

使用{client_access_token}作为access_token已解决此问题

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM