0

I'm setting up a Google Sheet to download data from my Next device and would like it to run unattended.

I've been using OAuth2 for Apps Script to provide access tokens. Unfortunately, the authorization tends to expire every seven days and needs to be reapplied. I also looked into ScriptApp.getOAuthToken(), but it can't access my Nest project, probably because it hasn't been authorized.

My ideal solution would be to remove the bulk of the authorization code needed by OAuth2 for Apps Script, but I'll happy settle for just not having to log in every week just to re-auth the project.

Is what I'm looking for possible? If so, how do I go about it?

Joe Moore
  • 43
  • 3
  • Nest's access token is not the same as you Google's account token. And what you should try to get is a refresh token, so you can get access tokens after they expire. – Martí Mar 16 '21 at 14:36
  • I was hoping that, since Nest had been brought into the fold, that perhaps the ScriptApp token would work for Nest. If I'm wrong, that's okay. I poked through the OAuth2 for Apps Script code and found a `refresh()` function, so hoping setting that to a daily trigger will stave off re-auths. – Joe Moore Mar 17 '21 at 20:30
  • I feel like you would really learn from reading about how OAuth 2.0 works in general (it's a standard). Refresh uses a refresh token to generate a new access token. It's used when the request fails because the access token or if the access token expired. It's not something you do "once a day" just in case. Just try to make a request and if it fails with an specific error code, try refreshing the token. Also, note that your access could be revoked at any time so your application should take that into account. – Martí Mar 18 '21 at 16:36
  • I've already had to provide a three-legged auth server implementation for work, so I'm well aware of how OAuth 2 works. This is also why I'm happy to let someone else do the heavy lifting in the client side. This is a hobby project with for myself, so not worried about providing a full flow. – Joe Moore Mar 19 '21 at 17:10

2 Answers2

0

I'm having the same problem. The documentation says that an app with a "Testing" publish status will only get a refresh token for 7 days. The issue isn't the access token which only lasts for 1 hour. Basically, unless you certify the app with google they won't let you refresh the access token for more than 7 days. Very annoying as I'm not trying to write an app I want to release! I'm tinkering with my own home and nothing more. I hope google will reconsider how they provide access for individual projects...

Andy
  • 1
  • Thanks for catching this! Could you include a link to the docs where the 7 day limit is called out? Google usually has a feedback option on pages, and I'd like to add some! – Joe Moore Mar 27 '21 at 11:01
0

On the consent page just publish the app to production. There should be no need to have it verified by Google as it is internal. You will just get unverified app when you log in. But no need to relogin every 7 days.

  • Thanks, Martin. I had set it to published and was fairly certain it was still requiring re-authentication. Either way, I haven't been prompted for a couple weeks, so I think we can call this closed. – Joe Moore Apr 22 '21 at 22:28