gs4 auth not working on heroku build

I am trying to get my script to run on Heroku. I get the build on Heroku and have it scheduled to run once a day at 4 p.m. The issue is with my script. I am using googlesheets4 to update Sheets tables. I cannot get it to do the authorization. Attached is a screenshot of the most recent log. Any advice would be helpful, not sure if this is a Heroku issue or a me issue.

gargle (which takes care of all the auth stuff having to do with Google, e.g. googlesheets4, gmailr, etc) has a vignette (linked to in the bottom of your error message) that should help you with non-interactive authorization. The approach you'll take likely depends on your needs, so it's worth a careful read:

I've tried the one that should work for me and a few others on that page with no success. Is it because I am trying to write to a sheet? I've tried the project-level OAuth cache which should be the one to work for me, but it does not work. Anytime Heroku see the gs4_auth() is errors.

Hmm…I am not sure, tbh. Have you taken a look through the googlesheets4 issues to see if anyone has encountered anything similar?

Also might be worth looking through the gargle issues.

I was able to figure it out. I was not committing the .secrets file along with the R scripts. This is what I have in my script allow Heroku to upload into sheets.

gs4_auth(cache = ".secrets")
gs4_auth(cache = ".secrets", email = TRUE)

Here is what I ran to commit.

git add init.R file-name.R -f .secrets
git commit -am "commit reason"
git push heroku master

Maybe this is because I am new to R, but it was not clear in the gargle documentation that the .secrets file needed to be uploaded. I came across this information in this issue. Hopefully this can help someone else.

You might want to file an issue in the gargle repo suggesting they add that to the documentation. I'm sure others would appreciate it in the future.

You're right, added the issue. Thank you!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.