Med Besbes
Med Besbes

Reputation: 2021

how to connect from java to google sheet using GoogleIdToken

I want to connect to google sheet using google java client library. I tried the following tutorial and it works fine.
Here after an example using client_secret.json file

InputStream in = Quickstart.class.getResourceAsStream("/client_secret.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
                        clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();

What I want is to connect to google sheet not using client_secret.json file but using GoogleIdToken object.
is it possible?

GoogleIdToken from lib com.google.api.client.googleapis.auth.oauth2.GoogleIdToken

Upvotes: 1

Views: 206

Answers (1)

ReyAnthonyRenacia
ReyAnthonyRenacia

Reputation: 17613

I think GoogleIdToken is mainly for signing in to websites with use of google accounts. However this is not enough authorization since in the case of Sheets API, you are now making calls to Sheets API library that's why you need the client_secret.json to give you authorization. So I dont think you can use GoogleIdToken alone. You may also read Using OAuth 2.0 for Web Server Applications for more info.

Upvotes: 1

Related Questions