We want to implement Google OAUTH to play nicely with our web-app based credentials. Flow starts on UI side, which shows user consent screen, and then we obtain a code. That code is then sent to our java based back-end to get refresh token.
At the moment we use this approach:
private Analytics getAnalytics(String refreshToken) throws Exception {
NetHttpTransport httpTransport =
GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory =
JacksonFactory.getDefaultInstance();
return new Analytics.Builder(
httpTransport,
jsonFactory,
new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setClientSecrets(clientId, clientSecret)
.build()
.setRefreshToken(refreshToken)
).build();
}
The problem in above is that GoogleCredential is deprecated. What is they non-deprecated way to do this?
We are using following lib:
com.google.apis.google-api-services-analytics:v3-rev20190807-1.30.10
Google Credential is not fully deprecated, it depends on the library you are using (com.google.auth:google-auth-library-oauth2-http:0.17.1 should still work)
An any case, as mentioned here the non-deprecated way is to use Google Auth Library for Java
There are samples for different ways to build the credentials - depending on your use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With