r/GoogleAppsScript • • Apr 12 '25

Question What are the differences between Apps Script OAuth and Service Account?

Hi all,

I started coding with Google Apps Script and used Google Apps Script OAuth to connect to advanced services multiple times. A simple ScriptApp.getAuthToken() with permission on appsscript.json file allows me to retrieve Sheets API. On the other hand, I heard about setting up a service account could do the same, and I don't have to worry about 7-day reauthorization. I tried to search/AI but none give me useful information, so I just want to ask what are the differences between a service account and an Apps Script Oauth, and which should I use for automation workflow that require API connection?

2 Upvotes

12 comments sorted by

View all comments

Show parent comment

3

u/WicketTheQuerent Apr 14 '25

I think you should change your approach. Instead of using the Google Apps Script web app to return an OAuth token, use it to return the needed data.

Another option is to access the APIs you need directly from your website. The Google Sheets API has a quickstart for JavaScript -> https://developers.google.com/workspace/sheets/api/quickstart/js

If you still insist on using a service account,, here is the link to the example for uint the Google Apps Scriipt OAuth Library with a service account -> https://github.com/googleworkspace/apps-script-oauth2/blob/main/samples/GoogleServiceAccount.gs

1

u/geminiikki Apr 14 '25

Thank you, very much appreciate