Closed nicocriscuolo closed 5 years ago
You need to deploy the oauth file on the server as well, this is the same as the previous versions of gmailr
Thank you very much for the answer Jim.
Actually I have deployed also the .httr-oauth file online but the screen remains white, waiting for the browser authentication. When I created the .httr-oauth file launching the shinyapp for the first time (with the above mentioned functions at the beginning of my server) I was working locally, and the file automatically was inserted in the working directory of my app.
Now if, locally, I restart the session and remove only the gm_auth_configure function, after launching the app in the new session (always locally) I get the following error message:
Error : Can't get Google credentials. Are you running gmailr in a non-interactive session? Consider: Call gm_auth()
directly with all necessary specifics.
That's way I think that for working locally I always also need to specify the path of my .json file through the gm_auth_configure function.
As concern the shinyapp deployed online, even though the two functions are present at the beginning of the server, inside my logs I get the following error message:
I am wondering if the .httr-oauth works just locally and maybe the issue is determined by something that I should set directly on the Google Cloud Platform.
What do you think?
Thank you so much for your availability.
Jim,
I don't know if it would be a solution, but maybe I have understood the source of the problem. My shiny app uses also a token generated from the package rdrop2 to upload files in dropbox, and the .httr-oauth file has the same name of the one generated every time with gmailr.
That's way my token is overwritten and the application can't get the credentials. By your knowledge, do you think it's possible to rename the .httr-oauth file generated with gmailr or producing it directly with a different name?
Best,
Nico
See the documentation in gargle with how to test the directory where the oauth tokens are stored https://gargle.r-lib.org/articles/non-interactive-auth.html#create-a-cache-for-a-specific-project, the short answer is you can use options(gargle_oauth_cache = ".secrets")
to set the location to wherever you would like for a specific project.
I tested the token created after having removed the one for the rdrop2 package, but it still doesn't work online. Is there some guidelines of the specific operations to do for setting up gmailr specifically for an online shinyapp? For example, with the last version in my code I had just the functions for e-mail composition and send message, the .httr-oauth file was stored in my project folder and everything was ok, but now I don't know if the initial passages for the configuration, done through gm_auth_configure and gm_auth are right or not. For example, I don't understand while I keep obtaining the message "Google Credentials not found" if at the beginning of my server there's the function "gm_auth(email = "authorized_email", path = "MY_JSON.json").
Thank you again for your help!
Error: Can't get Google credentials.
Are you running gmailr in a non-interactive session? Consider:
* Call `gm_auth()` directly with all necessary specifics.
I get the same errors (above) while running locally too. The gm_auth() fails even though the auth token is lying in the current working directory. There is no redirection to a browser like earlier version used to do.
I also tried
gm_auth(token = ".httr-oauth")
or
gm_auth(path = "mass_mailer.json")
But situation does not improve. It keeps saying:
Error: Can't get Google credentials.
Are you running gmailr in a non-interactive session? Consider:
* Call `gm_auth()` directly with all necessary specifics.
What could be wrong?
You need to call gm_auth_configure()
to setup the oauth app before calling gm_auth()
.
You need to call
gm_auth_configure()
to setup the oauth app before callinggm_auth()
.
It worked. Sorry for jumping the gun. Have a nice evening!
Good to hear, in 86627e9 I made the error message more clear when you call gm_auth()
before calling gm_auth_configure()
. I also added some more documentation to the readme.
Hi @jimhester and @sanjmeh, thanks for your clarification. I've followed the procedure inside the README.Rmd, but I still the application doesn't work online, but just locally. Here's a list of what I did:
after downloading the "credentials.json" in my working directory ("App") I called, at the beginning of my server.R, the functions gm_auth_configure(path = "credentials.json")
and gm_auth()
by simply starting my shiny app locally;
I got redirected to a new page and so I configured my gmail account;
everytime I run my app locally, at the beginning of my server I have this to functions: gm_auth_configure()
and gm_auth(email = "my_email@gmail.com")
, and the emails are sent correctly;
3.1. ps: this time, after configuration, no .httr-oauth file has been "automatically" created. When I send an e-mail through the app that is running locally, in the R console i can see the message "Auto-refreshing stale OAuth token".
Now the ONLINE part on shinyapps.io:
4.1. if I deploy my shinyapp with the functions gm_auth_configure()
and gm_auth(email = "my_email@gmail.com")
at the beginning of the server (before server <- function..
) the app freezes at the start because there is no path for the .json file;
4.1. if I deploy the app by specifying gm_auth_configure("credentials.json")
and gm_auth(email = "my_email@gmail.com")
the app waits my authentication in browser before starting, and in my Logs, on shinyapps.io, I get always the same error (see attached image).
Again, the procedure to make it working locally works, but I still can't make it work online. Is there a step that I actually can't see?
Thanks again!
You need to copy both the credentials.json and your oauth token cache (e.g. in .secrets
to the server)
Jim, thanks. It's working now. For FUTURE REFERENCES, I am going to write all the workflow that I used to correctly set up the gmailr
functions to make a shiny App working on shinyapps.io, hope it can help someone else:
gmailr
README to download the .json file. It's important that in the creation phase of the .json key you "Desktop App";server.R
file (before server <- function(input, ..)
) insert the functions:options(gargle_oauth_cache = ".secrets")
;gargle::gargle_oauth_cache()
;gm_auth_configure(path = "data/credentials/MY-JSON.json")
;gm_auth()
;ui.R
and server.R
;server.R
remove the first two functions written above and just leave:gm_auth_configure(path = "data/credentials/MY-JSON.json")
;gm_auth(email = "CONFIGURED-EMAIL@gmail.com", cache = ".secrets")
;Best,
Nico
Hi Jim,
I have another small question related to this topic. Is it possible the file that has to be placed in the .secrets folder (sdasdjabq2eqw232342323GMAIL-ADDRESS@GMAIL.COM) expires after some time or there's the need to re-do the authorisation process? I'm asking this because few days ago, in my local folders, the folder .secrets was empty and I was unable to send emails from my app.
Thanks,
Nico
Hello and thanks a lot for this useful package!
I have some issues with the new version of gmailr. I followed the steps of the README and I have created a project on the Google Cloud Platform. I have downloaded the .json file and, locally, I have configured my account through the gm_auth_configure(), specifying my key ID and my secret. A popup allowed me to connect my Gmail account with my application. Then, I have used the function gm_auth(email = "my-email") to authorise every time just that e-mail to send messages from the app.
Now in my server I have:
If I launch the app locally it works, but every time I deploy it on shinyapp.io (including the .json file) it freezes waiting for a redirection of the browser.
By the way, after a launched my app locally, the .httr-oauth file was created in my project folder, but at this point I don't really know if I need to deploy also this file.
Could you please give me any suggestion to set up the right code to make the functions working also online?
Thanks!