I have a script running on my computer that should be able to manage my Google Drive content without asking me every time to connect.
From what I read on the internet, I should use service account credentials what I did.
The problem is I can't find any documentation / code example of how I should emplement my code to manage the content of the Drive ( create, delete, edit files etc...).
I have the following code:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
key_file_location = 'creds.json'
scopes = [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file'
]
credentials = ServiceAccountCredentials.from_json_keyfile_name(
key_file_location, scopes=scopes)
# https://developers.google.com/drive/api/v3/quickstart/python
service = build('drive', 'v3', credentials=credentials)
# Call the Drive v3 API
results = service.files().list(
pageSize=10, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print('No files found.')
else:
print('Files:')
for item in items:
print(u'{0} ({1})'.format(item['name'], item['id']))
This gives me the list of all the folder and files but I can't find a way to manage the files and folders. I was looking for something like service.files().create()
but can't find anything...
Would love to get some help !