pythongoogle-drive-apipydrive

I can see only files created with my script pydrive


As the title says I have an issue with pydrive. I ran the code given in the pydrive quickstart (https://googleworkspace.github.io/PyDrive/docs/build/html/quickstart.html) and I created a settings and credentials file to avoid entering my credentials all the time. But when I run this code:

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

# Rename the downloaded JSON file to client_secrets.json
# The client_secrets.json file needs to be in the same directory as the script.
gauth = GoogleAuth()
drive = GoogleDrive(gauth)

# List files in Google Drive
fileList = drive.ListFile().GetList()
for drive_file in fileList:
    print('title: %s, id: %s' % (drive_file['title'], drive_file['id']))

I can only see the files created with my script. For example if I add this before the list file:

folder = drive.ListFile({'q': "title = 'Python_test' and trashed=false"}).GetList()[0] # get the folder we just created

file = drive.CreateFile({'title': "test.txt", 'parents': [{'id': folder['id']}]})
file.Upload()

I only see the folder and the file ID I just created... And if I add manually a file on my drive (on my browser for example), it doesn't appear.

Anyone got an idea of what's going on?


Solution

  • I just found the problem, it was on my settings.yaml file, I added only this oauth_scope:

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

    but this gives only access to the files created by the app. To correct that I needed to remove the .file like this

    oauth_scope:
      - https://www.googleapis.com/auth/drive
    

    If you want more details about the different scopes, check this link: https://developers.google.com/identity/protocols/oauth2/scopes