Google drive api Java Google驱动器API错误

Google drive api Java Google驱动器API错误,google-drive-api,Google Drive Api,我正在尝试下载文件使用谷歌驱动器API使用的代码 private static void downloadFile(Drive service, File file) { //String fileId = "1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo"; OutputStream outputStream = new ByteArrayOutputStream(); try {

我正在尝试下载文件使用谷歌驱动器API使用的代码

 private static void downloadFile(Drive service, File file) {

        //String fileId = "1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo";
        OutputStream outputStream = new ByteArrayOutputStream();
        try {
            service.files().export(file.getId(), "application/pdf")
                    .executeMediaAndDownloadTo(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
}
每次我遇到此错误时:

com.google.api.client.http.HttpResponseException: 403

    Forbidden
    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "insufficientPermissions",
        "message": "Insufficient Permission"
       }
      ],
      "code": 403,
      "message": "Insufficient Permission"
     }
    }

            at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1070)
            at com.google.api.client.googleapis.media.MediaHttpDownloader.executeCurrentRequest(MediaHttpDownloader.java:245)
            at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:199)
            at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAndDownloadTo(AbstractGoogleClientRequest.java:562)
            at com.google.api.services.drive.Drive$Files$Export.executeMediaAndDownloadTo(Drive.java:3402)
            at Quickstart.downloadFile(Quickstart.java:162)
            at Quickstart.main(Quickstart.java:130)

有人知道我哪里做错了吗?

线索是许可不足。这是不言自明的。但如何解决这是一个问题?这有点像说如何解决无效密码。您的应用程序没有读取该文件的权限。仅此而已。Scope已设置为私有静态最终列表SCOPES=Arrays.asListDriveScopes.DRIVE;它提供了完全访问权限。对于调用此方法的所有文件,我仍然面临此错误。请检查您在驱动器服务中传递的凭据是否与该文件来自的帐户相同。许多人错误地为服务帐户生成凭据,然后试图将其应用到自己的Google帐户。