Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
How to use access token from google calendar in js

I have question regarding google calendar, and hope you can help me.

I have access_token from google calendar and that access_token was stored in localStorage.

          const googleAccessToken = e.vc.access_token;
          localStorage.setItem('googleAccessToken', googleAccessToken);

Now please help me understand how can I use this to avoid authorization every time.

For example I want to delete all events, And for that I wrote this code, and this code every time wants from me authorization:

   const handleDisconnect = () => {
    gapi.load('client:auth2', () => {
      console.log('loaded client');

      gapi.client.init({
        apiKey: API_KEY,
        clientId: CLIENT_ID,
        discoveryDocs: DISCOVERY_DOCS,
        scope: SCOPES_CLEAR,
      });
      gapi.client.load('calendar', 'v3', () => {
        console.log('sdsd');
      });
      gapi.auth2
        .getAuthInstance()
        .signIn()
        .then(() => {
          var events = bb;
          var makeRequest = resource => {
            console.log(resource);

            var request = gapi.client.calendar.calendars.clear({
              calendarId: 'primary',
            });

            request.execute(resp => {
              console.log(resp);
            });
          };

          for (var j = 0; j < events.length; j++) {
            makeRequest(events[j]);
          }
        });
    });
    };

Please help me to fixed that code with access_token for avoiding authorization

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Access tokens expire after one hour. Once the access token has expired you will need to authorize the user again order to have access to their data again.

Normally with Oauth2 you can request something called off line access this will then give you something called a refresh token. Refresh tokens for applications that are in production are long lived and for the most part do not expire. You can use a refresh token to request an new access token when ever needed. This way you will not need to authorize the user after an hour.

Unfortunately refresh tokens are not supported by client sided authorization using JavaScript. You will need to switch to a server sided language.

If you are trying to access a static calendar account owned by you the developer as opposed to calendar accounts owned by your users you could use something called service accounts. However service accounts only work with Google calendar if you use domain wide delegation to a google workspace account it will not work with standard Gmail calendar accounts. Also service accounts are not supported by JavaScript you will need to switch to a server sided programming language.

After all that I hope you can see if you are sticking with JavaScript you will need to request authorization of your users when ever the access token expires.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!