使用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.
我尝试了:
-
请求主体内容类型:'application / vnd.google-apps.spreadsheet',media_body content-type:'text / csv'。 - > 401错误请求
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