0

Sorry for my poor english and i am a beginner of pydrive user. now i am trying to get all the files names from my google drive. here is my drive.py:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.CommandLineAuth()
drive = GoogleDrive(gauth)

file1 = drive.CreateFile({'title': 'Hello.txt'})  # Create GoogleDriveFile instance with title 'Hello.txt'.
file1.SetContentString('Hello World!') # Set content of the file from given string.
file1.Upload()

for file_list in drive.ListFile({'q': "'root' in parents and trashed=false"}):
  print('Received %s files from Files.list()' % len(file_list)) # <= 10
  for file1 in file_list:
      print('title: %s, id: %s' % (file1['title'], file1['id']))

and here is my setting files:

client_config_backend: settings
client_config:
  client_id: XXXX
  client_secret: YYYYY

save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json

get_refresh_token: True

oauth_scope:
  - https://www.googleapis.com/auth/drive.file
  - https://www.googleapis.com/auth/drive.install
  - https://www.googleapis.com/auth/drive.metadata

and there is the result:

Received 1 files from Files.list()    
title: Hello.txt, id: xxxxxx

the question is , i can only get the files 'hello.txt' that created above but not only created from the webinterface in goole drive. Is there any wrong inside my setting file or query?

Sorry again for my poor english and hope everyone will have a nice day.

chw
  • 41
  • 4
  • See what happens when you change `drive.file` scope to `drive` scope. – tehhowch Jun 21 '18 at 03:54
  • Dear, Thanks for the reply After changed from drive.file->drive, the result is same and i only can receive the file list that created by my scripts, and all the files that existing in the google drive. – chw Jun 21 '18 at 04:15
  • Who does your script execute as - you, or a service account? – tehhowch Jun 21 '18 at 04:28
  • Dear,I execute as myself by just >>python3 drive.py in the terminal. Sorry i had something wrong that all the files that existing in the google drive i can not receive. – chw Jun 21 '18 at 04:35
  • Dear, Finally i fixed it by delete the credentials.json, edit the yaml files and run again, it runs fine! – chw Jun 21 '18 at 08:47

0 Answers0