使用Drive v2 API将CSV上传到Google云端硬盘电子表格 [英] Upload CSV to Google Drive Spreadsheet using Drive v2 API

查看:347
本文介绍了使用Drive v2 API将CSV上传到Google云端硬盘电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Drive API v2 将本地 CSV 文件上传到Google云端硬盘,以便上传的文件位于本机Google电子表格格式。

How can I upload a local CSV file to Google Drive using the Drive API v2 so that the uploaded file is in the native Google Spreadsheet format. Preferably in Python, but a raw HTTP request will suffice.

我尝试了:


  1. 请求主体内容类型:'application / vnd.google-apps.spreadsheet',media_body content-type:'text / csv'。 - > 401错误请求

  1. request body content-type: 'application/vnd.google-apps.spreadsheet', media_body content-type: 'text/csv'. --> 401 Bad Request

请求正文内容类型:'application / vnd.google-apps.spreadsheet',media_body content- vnd.google-apps.spreadsheet。 - > 400错误请求

request body content-type: 'application/vnd.google-apps.spreadsheet', media_body content-type: 'application/vnd.google-apps.spreadsheet'. --> 400 Bad Request

...(其他几个人,例如离开某个财产和类似内容,通常是400或驱动器无法识别作为原生电子表格)

... (a couple of others such as leaving a property out and similar, usually got 400 or Drive didn't recognise it as a native spreadsheet)


推荐答案

c $ c> text / csv 作为内容类型。
获取文件转换的诀窍是将?convert = true 查询参数添加到请求url:

Your insert request should specify text/csv as the content-type. The trick to get the file converted is to add the ?convert=true query parameter to the request url:

https://developers.google.com/drive/v2/reference/files/insert

这篇关于使用Drive v2 API将CSV上传到Google云端硬盘电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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