0
votes

I'm trying to integrate with one of Google Cloud REST APIs.

Using simple rest client I can generate short term API token using gcloud CLI:

curl -H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" ....

I want to do it now with simple Java client... Of course - it's easy to perform REST calls using code. But how do I produce the API token?

I tried the instruction at the bottom of this page:

https://developers.google.com/identity/protocols/OAuth2ServiceAccount

But the generated token is not working well.

1
What do you mean when you say that the token is not working well? If you are getting an error message, could you post it?Joan Grau Noël

1 Answers

-1
votes

I think you might want to check the specific documentation for Using OAuth 2.0 with the Google API Client Library for Java

You have two authentication methods like Google Credential and Google App Engine identity.

Per the documentation that you shared, you might want to keep using Google Credentials, here's an example of how it looks a request.

GoogleCredential credential = new GoogleCredential().setAccessToken(accessToken);
Plus plus = new Plus.builder(new NetHttpTransport(),
                             JacksonFactory.getDefaultInstance(),
                             credential)
    .setApplicationName("Google-PlusSample/1.0")
    .build();