Google API Client Library for R: googleAuthR v0.1.0 now available on CRAN

One of the problems with working with Google APIs is that quite often the hardest bit, authentication, comes right at the start.  This presents a big hurdle for those who want to work with them, it certainly delayed me.  In particular having Google authentication work with Shiny is problematic, as the token itself needs to be reactive and only applicable to the user who is authenticating.

But no longer! googleAuthR provides helper functions to make it easy to work with Google APIs.  And its now available on CRAN (my first CRAN package!) so you can install it easily by typing:

> install.packages("googleAuthR")

It should then load and you can get started by looking at the readme files on Github or typing:

> vignette("googleAuthR")

After my experiences making shinyga and searchConsoleR, I decided inventing the authentication wheel each time wasn't necessary, so worked on this new R package that smooths out this pain point.

googleAuthR provides easy authentication within R or in a Shiny app for Google APIs.  It provides a function factory you can use to generate your own functions, that call or do the actions you needed.

At last counting there are 83 APIs, many of which have no R library, so hopefully this library can help with that.  Examples include the Google Prediction API, YouTube analytics API, Gmail API etc. etc.

Example using googleAuthR

Here is an example of making a R package using googleAuthR:

If you then want to make this multi-user in Shiny, then you just need to use the helper functions provided:

17 responses
I'm currently looking into the code base because I believe it's incorrectly parsing the `redirect_uri` where `` is incorrectly parsed as ``. I get the following return from Google ```400. That’s an error. Error: redirect_uri_mismatch The redirect URI in the request: did not match a registered redirect URI. ``` Perhaps it's this series below? ``` url
Dear mshmei, thanks for the report! Also try the github page as it's easier to keep track and give examples. But to your issue, may I ask what type of url you are putting in the Google dev console? It's there it looks, and then should auto detect where your shiny app is running. Also I guess you are using github version, or is it CRAN? You have to launch the app specifying the port in your app. It's working for fine for me and others so I suspect it's your setup at the moment rather than a bug, but obviously want to help either way :)
Ah, perhaps its because you have put a port number on a web URL. You just need to put in the URL, and it will default it port :80 which is web traffic, so in your example in the Google Dev console you need to put in - you only add the port number for localhost and
Hey Mark, thanks for the response. The reason was because I attached a port number to the web URL. I was able to fix this by letting it just default to port 80.
Hey mark, this is only loosely related but I was wondering if you were familiar with storing any from session$clientdata in the browser's cookies? If you recall our dialogue from last time, I was able to use your package and some additional tools (Google + API) to validate user e-mails. I was wondering if there was a way to store the validation in cookies?
Hi Mshmei, Shiny doesn't directly support cookies so you will need to use javascript to read this and then put it into Shiny yourself, I've not done it myself but this Stack Overflow question has some details: . You may instead use local storage via this shinyStore package but don't keep anything private in there.
Hey dude, I found this resource here. You were right, javascript is necessary from the looks of it.
Hi Mark, Was wondering if we could use this to access Youtube Analytics API, if yes then what would be the scope in the options?
Hi Tabu, yes it should work with YouTube analytics too, get started at the help docs here: In there it states the scope to be Happy APIing :)
Thanks a lot Mark :)
Hi Mark, is there a way to automatically close the browser window after logging in using the gar_auth(new_user =TRUE) command? Or to get the reference to the window instead?
Hi Khoa, it depends on your use case, if its just one user then you may want to try service authentication instead (gar_auth_service()) which doesn't need the pop-up, or if its multi-user log ins so you need some manual interaction, then have a look at the library RSeleium.
Hi Mark, If gar_auth() return the reference to the login window along with the token then I can easily close it using javascript. Is that also possible? Thanks!
Good timing Khoa - I just released version 0.4 which has JavaScript authentication, which will open/close for you. A demo of it is here:
3 visitors upvoted this post.