简体   繁体   English

Google Drive API无法找到任何文件夹

[英]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): 我正在尝试获取我在Google云端硬盘(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. results.files是一个空数组。

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. 如果我在此处尝试相同的查询, 请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我看到了我的所有文件夹。

Also, if I remove query I can see all my files but not folders. 此外,如果我删除查询,我可以看到我的所有文件,但不能看到文件夹。

UPD. UPD。 I found it doesn't see any other files except Getting started pdf. 我发现除了入门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 我做了什么:在Google云端硬盘界面中我选择了文件夹,然后点击“分享”并输入来自凭据的电子邮件:xxx@yyy.iam.gserviceaccount.com

That's weird but worked. 这很奇怪但很有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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