简体   繁体   中英

Google Drive API can not find any folder

I'm trying to get a list of folders that I created in Google Drive (Python, Flask):

SCOPES = ['https://www.googleapis.com/auth/drive']
drive_credentials = service_account.Credentials.from_service_account_file(
                json_url, scopes=SCOPES)    
drive_service = build('drive', 'v3', credentials = drive_credentials)
        results = drive_service.files().list(
             q="mimeType='application/vnd.google-apps.folder'", 
             spaces='drive').execute()

results.files is an empty array.

I can not figure out what is wrong. If I try the same query here https://developers.google.com/drive/api/v3/reference/files/list?apix_params=%7B%22q%22%3A%22mimeType%20%3D%20%27application%2Fvnd.google-apps.folder%27%22%7D I see all my folders.

Also, if I remove query I can see all my files but not folders.

UPD. I found it doesn't see any other files except Getting started pdf. I created just couple of test files and the query has still only one result.

I found what was the problem. Even although the scope gave "the full access" it actually did not. Only after I gave permission to my own email it started working.

What I did: in the Google drive interface I selected folders, then click "Share" and entered the email from credentials: xxx@yyy.iam.gserviceaccount.com

That's weird but worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM