且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何通过Google API客户端库传递正文?

更新时间:2022-10-25 08:41:08

这里有一个微妙的细节 - 请求应该是表格资源,如果你想更新它; 内容(在本例中为行)实际上应作为媒体上传进行传递。

在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.)