使用Python在Facebook上进行搜索 [英] Using Python for Facebook to search

查看:102
本文介绍了使用Python在Facebook上进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use Python to search the Facebook Graph for Pages. When I use the Graph API Explorer on the Facebook webpage and I enter:

search?q=aquafresh&type=page

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

I get the results I'm looking for. When I do the same in Python (after installing the PythonForFacebook module):

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

我相信我可以正确地识别令牌,使用的是与网页相同的令牌,并且该令牌可以在网页上使用.我还可以在Python中进行基本查询(例如,查询我"可以正常工作)

I believe I'm properly identifying with the token, I'm using the same one as the webpage and it works on the webpage. I'm also able to do basic queries in Python (e.g., querying for "me" works fine)

推荐答案

我想出了一种不使用Facebook Graph API的方法.而是使用Requests库:

I figured out a way to do this that doesn't involve the Facebook Graph API. Instead, use the Requests library:

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

这篇关于使用Python在Facebook上进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆