Since this is the first time front-end development experience, I need put google calendar on my webApp, but google oauth didn’t give me the refresh_token to do CRUD on calendar
I knew the google oauth process is:
- sent request url to google oauth server
- google prompts user for consent
- get oauth server response :
the response is like
{
'access_token':...,
'expires_in':...,
'scope':...,
...,
'refresh_token:,
}
i’ve ask chatgpt that need set access_type='offline'
and prompt: 'consent'
, but it can’t work
the partial code is blew:
function gisLoaded() {
tokenClient = google.accounts.oauth2.initTokenClient({
client_id: CLIENT_ID,
scope: SCOPES,
callback: '', // defined later
access_type: 'offline',
prompt: 'consent'
});
gisInited = true;
maybeEnableButtons();
}
function maybeEnableButtons() {
if (gapiInited && gisInited) {
// Enable the authorize button here
}
}
function handleAuthClick() {
tokenClient.callback = async (resp) => {
if (resp.error !== undefined) {
throw (resp);
}
setIsAuthorized(true);
setAuthToken(gapi.client.getToken().access_token); // Save the token
await createNewCalendar();
};
if (gapi.client.getToken() === null) {
tokenClient.requestAccessToken({ prompt: 'consent' });
} else {
tokenClient.requestAccessToken({ prompt: '' });
}
}
the response from google, which lack of refresh_token field
Can anyone help me?
greatly appreciated! thanks