使用drive.file范围执行查询时出现错误500 [英] Error 500 when performing a query with drive.file scope
问题描述
此代码在"https://www.googleapis.com/auth/drive"范围内可以正常运行
This code runs fine with the scope "https://www.googleapis.com/auth/drive"
File folderEntry = drive.files().get("XXXXj0_srDPPGUEtHaVYtZFljMEk").execute();
String driveQuery = "title = '" + "test" + "' and mimeType = 'application/vnd.google-apps.folder' and ";
driveQuery += "'" + folderEntry.getId() + "' in parents";
Files.List request = drive.files().list();
request.setQ(driveQuery);
FileList files = request.execute();
但是,如果我在凭据中和API客户端访问面板中将范围更改为"https://www.googleapis.com/auth/drive.file",则会引发错误500.
But if I change the scope to "https://www.googleapis.com/auth/drive.file" in the credentials, and in the API Client access panel, an error 500 is thrown.
500 Internal Server Error { "code" : 500, "errors" : [ {
"domain" : "global",
"message" : "Internal Error",
"reason" : "internalError" } ], "message" : "Internal Error" }
我正在使用服务帐户,并且父文件夹是由应用程序创建的.
I am using a service account and the parent folder was created by the application.
我不明白为什么我无法执行此查询.
I do not understand why I cannot perform this query.
推荐答案
这可能有点晚了,但是...我相信会出现此问题,因为当您使用范围
This may be a bit late but... I believe the problem occurs because when you run with the scope https://www.googleapis.com/auth/drive.file you are only allowed to see the files your app has created. However, your query may potentially return metadata that are outside your auth scope.
我也遇到了同样的问题,并通过添加添加 DRIVE_METADATA_READONLY范围来设法解决该问题:
I had the same problem as well and manage to fix it by adding the DRIVE_METADATA_READONLY scope:
credential = GoogleAccountCredential.usingOAuth2(this, DriveScopes.DRIVE_FILE, **DriveScopes.DRIVE_METADATA_READONLY**);
这篇关于使用drive.file范围执行查询时出现错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!