简体   繁体   English

如何在 Python 中格式化对 Blogger API 的获取请求?

[英]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?我究竟做错了什么?

request.get() method doesn't have blogID parameter. request.get() 方法没有 blogID 参数。 For more info use this link有关更多信息,请使用此链接

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.

相关问题 Blogger(Python)API:如何通过帖子ID检索帖子? - Blogger (Python) API: How do I retrieve a post by post ID? 我觉得我有很多 GET 请求,如何更有效地使用 api (python) - I feel I have to many GET requests, how do I use the api more efficiently (python) 如何通过使用 python 中的请求 package 发送 API 调用来获取 Smartsheet 中的所有行? - How do I get all the rows in a Smartsheet by sending an API call using the requests package in python? 如何使用 Python 3 和请求插入 API 分页? - How do I insert API pagination using Python 3 & requests? 如何使用 Z3 Python API 获得 SMTLIB 格式的求解器(问题)? - How do I get a solver (problem) in an SMTLIB format using the Z3 Python API? 如何在 Python 中格式化我对 Spotify Web API 的 GET 请求? - How do I format my GET request to the Spotify Web API in Python? 如何让 python 请求 package 工作? - How do I get python requests package to work? 如何在 Python 中使用 Google Blogger API? - How to use Google Blogger API with Python? 如何以所需的格式获取Python日期? - How do I get my Python date in the format that I want? 在python中开发时如何在post请求中使用“format=json&data=”? - How do I use "format=json&data=" in post requests when developing in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM