title: Getting error { "error" : "invalid_grant", "error_description" : "Token has been expired or revoked." } from Google oauth2 API
body: <p>I created an app in my google developer console account back in 2016 &amp; I have the client ID, client secret, access token &amp; refresh token for this app. I'm trying to read the emails from my Gmail account using the google:mail API in my apache camel application. It was working fine till today &amp; suddenly I am getting this error which says:</p>
  <pre><code>c.g.api.client.auth.oauth2.Credential    : unable to refresh token
  
  com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
  {
    &quot;error&quot; : &quot;invalid_grant&quot;,
    &quot;error_description&quot; : &quot;Bad Request&quot;
  }
      at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
      at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
      at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
      at com.google.api.client.auth.oauth2.Credential.executeRefreshToken(Credential.java:570)
      at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:362)
      at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
      at com.google.api.client.auth.oauth2.Credential.handleResponse(Credential.java:272)
      at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:999)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
      at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
      at org.apache.camel.component.google.mail.GoogleMailProducer.doInvokeMethod(GoogleMailProducer.java:49)
      at org.apache.camel.util.component.AbstractApiProducer$1.run(AbstractApiProducer.java:86)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  
  2020-07-20 11:31:02.689  WARN 20885 --- [CamelGoogleMail] o.a.camel.component.timer.TimerConsumer  : Error processing exchange. Exchange[ID-FVFXN5JKHV29-51050-1595224856126-0-2]. Caused by: [org.apache.camel.RuntimeCamelException - com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
  {
    &quot;code&quot; : 401,
    &quot;errors&quot; : [ {
      &quot;domain&quot; : &quot;global&quot;,
      &quot;location&quot; : &quot;Authorization&quot;,
      &quot;locationType&quot; : &quot;header&quot;,
      &quot;message&quot; : &quot;Invalid Credentials&quot;,
      &quot;reason&quot; : &quot;authError&quot;
    } ],
    &quot;message&quot; : &quot;Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.&quot;,
    &quot;status&quot; : &quot;UNAUTHENTICATED&quot;
  }]
  </code></pre>
  <p>Is this because the access token or the refresh token has expired today after 2016? Should I try resetting the client secret from the google developer console?</p>
  <p>EDIT - Here is the piece of code which I'm using</p>
  <pre><code>public GoogleMailComponent googleMailComponent() {
          GoogleMailConfiguration googleMailConfiguration = new GoogleMailConfiguration();
          googleMailConfiguration.setClientId(clientId);
          googleMailConfiguration.setClientSecret(clientSecret);
          googleMailConfiguration.setAccessToken(accessToken);
          googleMailConfiguration.setRefreshToken(refreshToken);
  
          GoogleMailComponent googleMailComponent = new GoogleMailComponent();
          googleMailComponent.setConfiguration(googleMailConfiguration);
          return googleMailComponent;
      }
  </code></pre>