MarkEdmondson1234 / googleAuthR

Google API Client Library for R. Easy authentication and help to build Google API R libraries with OAuth2. Shiny compatible.
https://code.markedmondson.me/googleAuthR
Other
175 stars 51 forks source link

Token seems to expire in shiny #145

Closed nasbar79 closed 5 years ago

nasbar79 commented 5 years ago

I access Google Analytics API via R with googleAnalyticsR. The whole thing happens in a Markdown script. Local everything runs without problems. But when I load the script on a Shiny Sever the GA token seems to expire after a while (a few hours).

The server log gives the following error message:

Warning in gzfile(file, mode) : cannot open compressed file '.httr-oauth', probable reason 'Permission denied'

The script to create the token looks like this:


library(googleAuthR)

options(googleAuthR.client_id = "client-id", googleAuthR.client_secret = "client-secret")

gar_auth()

I read that I should add


googleAuthR.httr_oauth_cache = FALSE

to the options. But when I do this and try to create a new Token I get follwing error:

Error: option('googleAuthR.httr_oauth_cache') must be set to valid cache file location, not TRUE or FALSE - (example: '.httr-oauth')

MarkEdmondson1234 commented 5 years ago

The tokens you generate last 60 minutes, so the RMarkdown script needs write access to it so it can refresh the token each time. You should specify that file using googleAnalyticsR's ga_auth("your.token") and not googleAuthR's gar_auth() I think, you only need googleAuthR if you have multiple APIs running.

Then upload the "your.token" file with your RMarkdown to the Shiny server, and make sure it has file permissions sufficient that your script can access and refresh it. (755 I guess)

nasbar79 commented 5 years ago

Thank you very much. I gave write permission to my app and that solved the problem. Apart from that I would like to know why I cant't set: googleAuthR.httr_oauth_cache = FALSE And what this setting is actually necessary for. Could you help me?

MarkEdmondson1234 commented 5 years ago

It doesn’t help you to set that option. For a start it doesn’t accept TRUE or FALSE and if you specify the filepath in ga_auth() then it is set for you more safely.