如何通过Google API客户端库传递正文? [英] How to pass body with Google APIs Client Library?
问题描述
我使用适用于Python的Google API客户端库与 Fusion Tables API 。这里 importRows 方法要求提供数据在身体里。我应该怎么做?
response = service.table()。importRows(tableId = TABLE_ID,body ='zzz,yyy ').execute()
返回错误 - 有一个意外的关键字参数body
。
这里有一个微妙的细节 - 请求应该是表格
资源,如果你想更新它; 内容(在本例中为行)实际上应作为媒体上传进行传递。
在python客户端中,这意味着您想要将某些内容传递给 media_body
参数,不是 body
。您不能传递文字字符串 - 您需要将数据封装在 MediaFileUpload 或 MediaInMemoryUpload 。 (对于这里的情况,你需要后者,但是如果你有一个磁盘上有行的文件,你需要前者。)
I use Google APIs Client Library for Python to work with Fusion Tables API. importRows method here requires to provide the data in the body. How should I do it?
response = service.table().importRows(tableId=TABLE_ID, body='zzz,yyy').execute()
returns the error - Got an unexpected keyword argument "body"
.
There's a slight subtlety here -- the body of the request should be the Table
resource, if you want to update it; the contents (in this case, the rows) should actually be passed as a media upload.
In the python client, this means you want to pass something in to the media_body
argument, not body
. You can't just pass a literal string -- you need to wrap the data in either a MediaFileUpload or MediaInMemoryUpload. (For the case here, you want the latter, but if you've got a file with rows on disk, you want the former.)
这篇关于如何通过Google API客户端库传递正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!