Reputation: 27
I am using the Google Drive API to create a .csv, and I see it in my "Drive" display but I don't see it in "Sheets." How can I make it show in Sheets? Here is my code:
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()
Upvotes: 0
Views: 3564
Reputation: 3614
Looks like you are just adding a CSV file to Drive.
You need to specify the mime type as Google Spreadsheet:
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()
Upvotes: 1