权限不足:请求的身份验证范围不足

时间:2019-10-24 12:08:33

标签: java google-api google-drive-api

我在共享Google驱动器文件时遇到问题。我用这种方法

OAuth运行得很好,我可以返回文件和文件夹,但是我不能更改共享权限,这是我的很多问题,我不知道为什么

JsonBatchCallback<Permission> callback = new JsonBatchCallback<Permission>() {
            @Override
            public void onFailure(GoogleJsonError e,
                                  HttpHeaders responseHeaders)
                    throws IOException {
                // Handle error
                System.err.println(e.getMessage());
            }
            @Override
            public void onSuccess(Permission permission,
                                  HttpHeaders responseHeaders)
                    throws IOException {
                System.out.println("Permission ID: " + permission.getId());
            }
        };

        BatchRequest batch = service.batch();

        Permission userPermission = new Permission()
                .setType("user")
                .setRole("reader")
                .setEmailAddress("mail@gmail.com");

        service.permissions().create(file_id, userPermission)
                .setFields("id")
                .queue(batch, callback);
        batch.execute();

是回应

{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Insufficient Permission: Request had insufficient authentication scopes.",
    "reason" : "insufficientPermissions"
  } ],
  "message" : "Insufficient Permission: Request had insufficient authentication scopes."
}

这是我的范围

Collections.singletonList(DriveScopes.DRIVE); //"https://www.googleapis.com/auth/drive"

0 个答案:

没有答案