0
votes
Code snippets for Building OAuth 2.0 credentials : 
    Credential credential = new GoogleCredential.Builder().setTransport(httpTransport)
                        .setJsonFactory(jsonFactory)
                        .setClientSecrets(myAppClientID, myAppSecret)
                        .build(); 
    credential.setRefreshToken(userRefreshToken);

I am using Java Library in order to get the Google Analytics Data.

I do have Client ID, Secret and Refresh Token. I am accessing Google Analytics API though this credentials information, My question is, Will Google OAuth 2.0 take care of Access Token Automatically? Or Do i need to handle it manually with some mechanism? If i am not passing access token to this code.

1
How did you get the refresh token? - Ján Halaša
@Ján Halaša Using RESTFul Service call. - Jay Panchal
Have you tried to run the code? Or replace the setRefreshCode() with setAccessToken()? You should already have an access token - you get all tokens in a single request - access token, refresh token and possibly ID token. - Ján Halaša
@Ján Halaša With above code i am getting data successfully. I haven't tried by replacing setRefreshCode() with setAccessToken(). As i want to know that, if i continue with the mechanism of only setting "Refresh Code" as mentioned in snippets...does it have any disadvantages? Or Is it like that.. still i need to pass the access code? Or Only Refresh code would be fine? - Jay Panchal

1 Answers

0
votes

From the Credential API doc:

Thread-safe OAuth 2.0 helper for accessing protected resources using an access token, as well as optionally refreshing the access token when it expires using a refresh token.

So if you don't specify an access token, it will be automatically fetched using the refresh token. But since you already have an access token, I would say it's good to set it - it will save the first network call to the /token endpoint.