I am using the Google Drive API as well as the Google Picker API on the frontend. My goal is to get users to authorize their drive account to be used, and subsequently be able to call the Google Picker API whenever they want without re-authorizing their drive.
// Authorizing client initially (I only want them to have to do this once)
await gapi.load("client:auth2", async () => {
clientInit = window.gapi.auth2.init({
client_id: driveClientId,
scope: driveScope,
});
await gapi.client.load('drive', 'v2', () => { handleAuthResult(clientInit) });
});
// Setting the access token (expires in 3600s)
async handleAuthResult(authResult) {
let signInResponse = await authResult.signIn();
let googleOAuthToken = signInResponse.wc["access_token"];
}
// Creating picker
new google.picker.PickerBuilder()
.addView(docsView)
.setOAuthToken(googleOAuthToken)
.setCallback(drivePickerCallback)
.build();
The picker has the .setOAuthToken(access_token) method that takes the access_token as a parameter. The one that you originally get after authorizing the drive expires in 1 hour, and its not giving me a refresh token to get another access token with. signInResponse.wc does not contain a refresh token.
I am confused as to how to get this refresh token, and then how to use it to get an access token, the documentation is not quite clear.