Skip to content

Instantly share code, notes, and snippets.

@MSK61
Created May 1, 2018 21:47
Show Gist options
  • Save MSK61/9a5cbdd083c4e024855986da67c4264f to your computer and use it in GitHub Desktop.
Save MSK61/9a5cbdd083c4e024855986da67c4264f to your computer and use it in GitHub Desktop.
import apiclient
import httplib2
import oauth2client.file
import operator
import re
files_api = apiclient.discovery.build('drive', 'v3', http=oauth2client.file.Storage('e:\creds.json').get().authorize(httplib2.Http())).files()
items = files_api.list(fields="files(id, name)", q="name = 'audioTest'").execute().get('files', [])
if items:
parent_id = items[0]['id']
print 'Parent folder:', parent_id
else:
print 'No files found.'
items = files_api.list(fields="files(id, name, mimeType)", q="'{}' in parents".format(parent_id)).execute().get('files', [])
if items:
print 'Files:'
for item in items:
print 'name={}, id={}, mimeType={}'.format(item['name'], item['id'], item['mimeType'])
else:
print 'No files found.'
# Changing MIME type doesn't work.
for cur_item in items:
if cur_item["mimeType"] == "video/ogg":
updated_file = files_api.update(fileId=cur_item["id"], body={"mimeType": "application/ogg"}).execute()
print '{} ({})'.format(updated_file['name'], updated_file['mimeType'])
import oauth2client.tools
import oauth2client.client
import oauth2client.file
oauth2client.tools.run_flow(oauth2client.client.flow_from_clientsecrets('e:\client_secret.json', 'https://www.googleapis.com/auth/drive.metadata'), oauth2client.file.Storage('e:\creds.json'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment