In my shiny app, I am using the gmailr function to authenticate my gmail account. On my local machine this works great. When I deployed my app it didn't work.
The expected result after running the following function is a popup asking me to choose which gmail account to authenticate. When I ran the app, instead of a pop-up, it showed the url to copy and paste in the logs instead of the pop-up appearing.
This is the following code in the app:
options(httr_oauth_cache=T)
gmailr::clear_token()
gmailr::gmail_auth()
Has anyone tried using this package in shinyapps.io?
1 Like
I think you probably have to upload the .httr-oauth
file created locally to the server. It's also possible you'll have to set the httr_oob_default
parameter. I'd recommend this article to generally get a better feeling for the topic: https://support.rstudio.com/hc/en-us/articles/217952868-Generating-OAuth-tokens-for-a-server-using-httr
And this QA might be helpful for you specifically on shinyapps.io: https://github.com/jennybc/send-email-with-r/issues/9
I think that your first two lines are conflicting -- in that the first says you want to cache your token and the second clears it. I'd suggest deleting the gmailr::clear_token()
line, assuming you're ok with cacheing your token.
3 Likes
Hi Alex,
Thanks for the suggestion!
I am still struggling unfortunately.
I changed my code to look like this:
options(httr_oauth_cache=T)
options(httr_oob_default=T)
gmailr::gmail_auth()
Then when this runs, it prompts me to copy and paste this token to my r-console.
4/GQF@JjszXNfafdjklafjdsalkfaeffaefklj (not real token)
Then when I copy and paste it into the rconsole, nothing happens after I paste it.
I also tried taking this token and copying and pasting it to the .httr-oath file and still no luck.
It would be really helpful if you can provide a simple sample code on how this could be done if you have experience with this. Appreciate the help so far!
Hi @nickknauer1,
If you do this right, it shouldn't ask for authentication on the server because the .httr-oauth
token is there already.
I'd recommend creating it locally and then copying it up when you go to shinyapps.io (option 3 here).
These are the steps:
- Run
options(httr_oob_default = TRUE, httr_oauth_cache=TRUE)
(maybe not necessary) on your local machine.
- Run
gmailr::gmail_auth()
on your local machine and follow the steps.
- Check that it worked correctly by running
gmailr::gmail_auth()
. If you hit enter and nothing happens, it's worked correctly.
- Find the file titled
.httr-oauth
(probably in the base directory of the project) and copy that with your project up to shinyapps.io.
Hope that's helpful!
1 Like
Hi Alex,
Thank you for the help!
This now works. Appreciate it.
Best,
Nick
1 Like
Hi @nickknauer1,
If you wouldn't mind, could you accept your favorite solution? You can do that by hitting the three dots next to Reply
and then the little check mark.
Thanks for being part of the community!