使用Python进行Facebook搜索

Dev*_*vin 2 python facebook facebook-graph-api

我正在尝试使用 Python 来搜索 Facebook 图表中的页面。当我在 Facebook 网页上使用 Graph API Explorer 时,我输入:

search?q=aquafresh&type=page
Run Code Online (Sandbox Code Playgroud)

我得到了我正在寻找的结果。当我在 Python 中执行相同操作时(安装 PythonForFacebook 模块后):

post = graph.get_object("search?q=aquafresh&type=post")
Run Code Online (Sandbox Code Playgroud)

我得到:

facebook.GraphAPIError: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api
Run Code Online (Sandbox Code Playgroud)

我相信我正确地识别了令牌,我使用与网页相同的令牌,并且它可以在网页上运行。我还能够在 Python 中执行基本查询(例如,查询“me”效果很好)

Dev*_*vin 5

我找到了一种不涉及 Facebook Graph API 的方法。相反,使用 Requests 库:

import requests
token = "your_token"
query = "your_query"
requests.get("https://graph.facebook.com/search?access_token=" + token +  "&q=" + query + "&type=page")
Run Code Online (Sandbox Code Playgroud)