0

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()
1
  • You may want to add the convert parameter to true when uploading the file which will trigger whether to convert this file to the corresponding Google Docs format. You can check this GitHub to see the implementation in python. Hope this helps. Commented Jun 13, 2017 at 15:58

1 Answer 1

1

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()

https://developers.google.com/drive/v3/web/manage-uploads#importing_to_google_docs_types_wzxhzdk18wzxhzdk19

Sign up to request clarification or add additional context in comments.

1 Comment

OK @ChrisLam, I am retracting my flag!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.