Syed Naeem
Syed Naeem

Reputation: 693

Unable to refresh access_token - google calendar api

Greetings my fellow developers I am working on a project where client needs to connect Google calendar with the project. I am using GAPI for connecting Google calendar with my application. Here is what I am doing:

step 1:

let config = {
    apiKey: [API_KEY],
    clientId: [CLIENT_ID],
    access_type: 'offline',
    discoveryDocs: ['https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest'],
    scope: 'https://www.googleapis.com/auth/calendar.events'
}
gapi.load('client:auth2', () => {
    gapi.client.init(config).then(() => {
        gapi.auth2.getAuthInstance().isSignedIn.listen(true);
    });
});

step 2:

Promise.resolve(gapi.auth2.getAuthInstance().signIn()).then(response => {
    store access_token, id_token, login_hint
}).then(() => {
    run_different_axios_requests_to_google_calendar();
});

or if I already have access tokens:

run_different_axios_requests_to_google_calendar();

Till this point it runs perfectly!

Problem comes when access token is expired, and read documentation and I found out that if you run gapi.auth2.getAuthInstance(). grantOfflineAccess() instead of gapi.auth2.getAuthInstance().signIn() you get refresh_token along with access_token, id_token, login_hint, but I don't get a response, in fact my promise shows that This app isn't verified, and i need refresh token for when access_token expires so that I can get new token, without having to ask user to signin again (via promise). I am not sure what I am doing wrong here! any help is appreciated!

Upvotes: 1

Views: 220

Answers (1)

Jessica Rodriguez
Jessica Rodriguez

Reputation: 2974

Here's a complete documentation from Google that let you to use the new JS library to unlock the power of Google Apps. It explained thoroughly the step by step procedure from authentication to using GAPI libraries like Calendar API.

Upvotes: 1

Related Questions