我正在使用Google Drive API创建.csv,我在“云端硬盘”显示屏中看到它,但我没有在“表格”中看到它。如何在表格中显示?这是我的代码:
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('drive', 'v3', http=http)
results = service.files().create(body={"name":"Test7.csv"}, media_body='/tmp/inputfile.csv', keepRevisionForever=None, useContentAsIndexableText=None, supportsTeamDrives=None, ocrLanguage=None, ignoreDefaultVisibility=None).execute()
答案 0 :(得分:1)
您似乎只是在向云端硬盘添加CSV文件。
您需要将mime类型指定为Google电子表格:
from apiclient.http import MediaFileUpload
file_metadata = {
'name' : 'My Report',
'mimeType' : 'application/vnd.google-apps.spreadsheet'
}
media = MediaFileUpload('test7.csv',
mimetype='text/csv',
resumable=True)
file = drive_service.files().create(body=file_metadata,
media_body=media,
fields='id').execute()