[英]How do I format get requests to Blogger API in Python?
I'm new to Python and API's.我是 Python 和 API 的新手。 I'm trying to work on a project and need some help.
我正在尝试一个项目,需要一些帮助。
I just want to request some information from Blogger to get back blog post details (title, body, etc) and return it.我只是想从 Blogger 请求一些信息,以获取博客文章详细信息(标题、正文等)并返回。
I'm wanting to use these: https://developers.google.com/resources/api-libraries/documentation/blogger/v3/python/latest/blogger_v3.blogs.html我想使用这些: https://developers.google.com/resources/api-libraries/documentation/blogger/v3/python/latest/blogger_v3.blogs.html
I can use requests.get(url/key)
and I get a server status[200]
, but everytime I try to find a way to use one of the requests from the link I get keyword errors.我可以使用
requests.get(url/key)
并获得服务器status[200]
,但每次我尝试找到一种方法来使用链接中的一个请求时,我都会收到关键字错误。
For example: "TypeError: request() got an unexpected keyword argument 'blogId'"
例如:
"TypeError: request() got an unexpected keyword argument 'blogId'"
My code is requests.get('url/key' blogId='BLOG ID HERE', x__xgafv=None, maxPosts=None, view=None)
我的代码是
requests.get('url/key' blogId='BLOG ID HERE', x__xgafv=None, maxPosts=None, view=None)
I don't feel comfortable posting my exact code, since it has my API in it.我不愿意发布我的确切代码,因为其中包含我的 API。
What am I doing wrong?我究竟做错了什么?
I am not sure, but oyu can use params like that:我不确定,但 oyu 可以使用这样的参数:
page = get('https://google.com', params={'blogId': '12345'})
It's better to look up information in the docs: https://requests.readthedocs.io/en/master/最好在文档中查找信息: https://requests.readthedocs.io/en/master/
I found my solution after digging a bit.经过一番挖掘,我找到了解决方案。
I was using get requests on the API to get a response, which is how it should be used.我在 API 上使用 get 请求来获得响应,这就是它应该使用的方式。
Yet, I was also trying to use a method of returning data that also used the get keyword, but was meant for use with the Google API Library.然而,我还尝试使用一种返回数据的方法,该方法也使用了 get 关键字,但它旨在与 Google API 库一起使用。
I had to install the Google API Client library and import build, and requests so that I could use the API methods instead.我必须安装 Google API 客户端库并导入构建和请求,以便我可以使用 API 方法。 This allows me to return results that are far more specific (hence the keyword arguments), and can be programmed to do a number of things.
这允许我返回更具体的结果(因此是关键字参数),并且可以通过编程来做很多事情。
Thanks everyone!感谢大家!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.