使用 2.0.0 google-api-client 进行 Gmail 调用时的兼容性问题

Gio*_*ana 5 java gmail google-api google-api-java-client gmail-api

google-api-client我一直在开发一个小项目,该项目连接到用户的 Gmail 收件箱并使用2.0.0 和google-api-services-gmail版本 v1-rev20220404-2.0.0读取邮件

当我尝试构建 Gmail 服务时

service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY,
          authorize).setApplicationName(Main.APPLICATION_NAME).build();
Run Code Online (Sandbox Code Playgroud)

它抛出一个 IllegalStateException 说

“您当前运行的是 2.0.0 版的 google-api-client。您至少需要 1.15 版的 google-api-client 才能运行 1.25.0 版的 Gmail API 库。”

起初我以为可能是我安装的模块不是最新的或者什么的,但这并没有真正意义,所以我尝试调试并进入了 Gmail.java 类。

该代码以非常简单的方式检查版本,如果条件为 false,则抛出异常

static {
        Preconditions.checkState(GoogleUtils.MAJOR_VERSION == 1 && GoogleUtils.MINOR_VERSION >= 15,
        "You are currently running with version %s of google-api-client. You need at least version 1.15 of google-api-client to run version 1.25.0 of the Gmail API library.",
        new Object[]{GoogleUtils.VERSION});
    }
Run Code Online (Sandbox Code Playgroud)

我认为这就是问题所在,我的 MAJOR_VERSION 为 2 且 MINOR_VERSION 为 0 使得该语句错误,即使我使用的版本是最新的。我不知道是否可以通过将 API 版本降级到 1.XX 来解决这个问题,无论如何我都会尝试,但是你知道我是否在这里做了什么吗?

Ste*_*eal 0

如果这对其他人有帮助,我在升级 Firebase 管理插件时遇到了此错误。它阻止我的 App Engine 应用程序启动。

对我来说,一个简单的修复方法是恢复我的 POM 文件。

修复:将 9.1.1 降级至 8.1.0:

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>9.1.1</version>
</dependency>

<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>8.1.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)