使用 Drive v2 API 将 CSV 上传到 Google Drive 电子表格 [英] Upload CSV to Google Drive Spreadsheet using Drive v2 API
问题描述
如何使用 Drive API v2 将本地 CSV 文件上传到 Google Drive,以便上传的文件位于原生 Google 电子表格> 格式.最好使用 Python,但原始 HTTP 请求就足够了.
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 内容类型:'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 内容类型:application/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 或 Drive 无法将其识别为原生电子表格)
... (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)
推荐答案
您的插入请求应指定 text/csv
作为内容类型.转换文件的技巧是在请求 url 中添加 ?convert=true
查询参数:
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 Drive 电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!