code: public Credential generateCredential() throws OAuthException {
      GoogleCredential credential = Strings.isNullOrEmpty(this.jsonKeyFilePath)
          ? generateCredentialFromClientSecrets()
          : generateCredentialFromKeyFile();
      try {
        if (!oAuth2Helper.callRefreshToken(credential)) {
          throw new OAuthException(
              "Credential could not be refreshed. A newly generated refresh token or "
              + "secret key may be required.");
        }
      } catch (IOException e) {
        throw new OAuthException("Credential could not be refreshed.", e);
      }
      return credential;
    }
docs: Generates a new offline credential and immediately refreshes it.
  
  @return a newly refreshed offline credential.
  @throws OAuthException if the credential could not be refreshed.