Skip to main content
 首页 » 编程设计

python之使用 Python for Facebook 进行搜索

2025年05月04日15xxx_UU

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

search?q=aquafresh&type=page 

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

post = graph.get_object("search?q=aquafresh&type=post") 

我得到:

facebook.GraphAPIError: Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api 

我相信我正确地识别了 token ,我使用的是与网页相同的 token 并且它在网页上有效。我还能够在 Python 中进行基本查询(例如,查询“我”工作正常)

请您参考如下方法:

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

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