ScriptApp.getOAuthToken() sometimes returns invalid token?

70 views
Skip to first unread message

Hoang Trinh

unread,
Oct 22, 2019, 4:14:22 AM10/22/19
to Google Apps Script Community

Hi everyone,

I have an add-on that has a time-based trigger that will run ScriptApp.getOAuthToken() every 1 hour and save into database.

The purpose of this is to get the user's OAuth token so that I can use it later outside of Google Apps Script (in Google Cloud Functions) to handle necessary tasks.

Most of the time, and for most of users, it works fine.

But for some users, and recently I experienced it myself, when I tried to use the OAuth token (get from database), I got the error.

Error: Invalid Credentials
    at Gaxios.request (/srv/node_modules/gaxios/build/src/gaxios.js:70:23)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
...

code: 401,
  errors: 
   [ { message: 'Invalid Credentials',
       domain: 'global',
       reason: 'authError',
       location: 'Authorization',
       locationType: 'header' } ] }


When I tried running ScriptApp.getOAuthToken() again to get new token, it works properly again. So I think it must be because the token itself is invalid.

How to fix this issue completely? Thank you.
Reply all
Reply to author
Forward
0 new messages