简体   繁体   中英

How can I obtain an OAuth refresh token for a G Suite Add-on running on Apps Script?

Does anyone know how to obtain a refresh token for a G Suite Add on, considering that the authorization flow to obtain the user consent was handled by Apps Script?

I know how to obtain the access token with the method

ScriptApp.getOAuthToken()

But I don't know how to obtain the refresh token for a particular user.

Context:

I have an add-on that allows users to schedule recurring meetings. The user grants the app access to their calendar when they install the add-on from the G Suite Marketplace, so I can read and write on their calendars when they are running the script.

I want to send them email reminders a day before a meeting, so I want to read their calendars in the background using a cloud function when they are not running the script.

In order to do that I would need to have the refresh token for that user since the access token expires.

I'm really stuck on this for many days now. Any help would be much appreciated!

Thanks a lot.

You have two options:

If you set access to offline ( .setParam('access_type', 'offline') ) it is enough if the user grants you permission once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM