Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compatibility problems when using 2.0.0 google-api-client for Gmail calls

I've been working on a little project that connects to the user's Gmail inbox and reads the mails using google-api-client 2.0.0 and google-api-services-gmail version v1-rev20220404-2.0.0

When I try to build the Gmail service

service = new Gmail.Builder(HTTP_TRANSPORT, JSON_FACTORY,
          authorize).setApplicationName(Main.APPLICATION_NAME).build();

it throws an IllegalStateException that says

"You are currently running with version 2.0.0 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."

At first I thought that maybe the modules I installed weren't up to date or something but it didn't really make sense, so I tried debugging and got in the Gmail.java class.

The code checks for the version in a really simple way, if the condition is false then it throws the exception

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});
    }

This is where the problem lies I think, my MAJOR_VERSION being 2 and MINOR_VERSION being 0 makes the statement false, even if the version I'm using is the latest. I have no idea if it can be solved by downgrading the API version to a 1.XX, I'll try anyway, but do you know if I'm onto something here?

like image 992
Giovanni Grana Avatar asked Aug 13 '26 06:08

Giovanni Grana


1 Answers

Solution is to upgrade to the v1-rev20230206-2.0.0 which is the latest version as of this writing

<dependency>
   <groupId>com.google.apis</groupId>
   <artifactId>google-api-services-gmail</artifactId>
   <version>v1-rev20230206-2.0.0</version>
</dependency>

Google documentation recommends searching for the lastest version here

like image 165
Dave B Avatar answered Aug 15 '26 21:08

Dave B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!