Automatic Google Sheets authorization in RShiny - r

I have an RShiny app that I had published online without any issues until this week. The app uses data stored in a Google Drive account, thus making use of the googlesheets package. When the app was working fine, I used gs_auth() to initially authorize and cache my Google credentials. Because my credentials were cached in a .httr_oauth in my working directory, it meant that when I ran the app's code, it wouldn't take me to a page in my browser that would ask me to authorize the account. When publishing the app to shiny.io, this cached .httr_oauth meant that the app would work online.
This week I made some changes to the app's code and when I ran the app it took me to the Google account authorisation page. There, I would click on the account and it would then say: "Sign in with Google temporarily disabled for this app".
After some looking I found that the googlesheets package is now outdated and I should instead be using the googlesheets4 package. However, after trying to authorize with that package (and the googledrive package) I'm able to get the app to run locally without it taking me to the Google account authorization page, but when I try to publish it still doesn't work. It always times out. Does anyone know what is going on? Anyone else having a similar issue?

I ran into this problem as well.
This outline worked really well for me.
https://gargle.r-lib.org/articles/non-interactive-auth.html
I would focus on Project Level OAthu part of the vignette.
The biggest issues I had for switching from "googlesheet" to "googlesheets4" was I forgot to install the "googledrive" package. The googledrive will allow you to use (drive_auth) and then build out from there as you can cache the authentication token.

Related

Unexpected error when querying Google Play Developer API

We have been trying to set up the sample app for Play Billing workflow with subscriptions as we are looking to introduce subscriptions in our app. We wanted to have the ClassyTaxi app running end to end in order to understand the flows better. Although for past 2 days, we are only trying to debug issues and/or missteps because of some really poor documentation on Google's front.
After ensuring every single step was correctly followed, we were able to make some progress and have the app working with the correct Skus as configured in Play Console. But now the backend server (ClassyTaxiServer) is throwing below error:
"Unexpected error when querying Google Play Developer API. Please check if you use a correct service account" - "OtherError: The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.".
We have relooked, recreated the service account on the Cloud Console several times, but no luck.
The Play Console is correctly linked with the Google Cloud project and the access is correctly granted to the service account.
Anyone has any suggestions? How can a sample app be so difficult to set up and function as expected? Or are we doing something terribly stupid?
Please help.
Thanks.
I passed trough similar situation, and I get same issue. After checking I found a note in google documentation saying the following:
Note: As of December 1, 2019, the Google Play Developer API is available only for version 3 and higher. If you're using a lower version of the API, you must migrate to version 3 by this date. For more information on migrating to version 3, see Changes to the Google Play Developer API.
Investigating the implemented code I found that the sample uses v2 of the google API (check ./subscriptions/play-billing/PlayBilling.ts line 70). So to avoid this situation, you will need to set it to v3, and update googleapis dependency to latest version in package.json.
Additional Notes
After solving this issue, I had a different message in 'OtherError', this time is “The current user has insufficient permissions to perform the requested operation.”. I will note my solution here just someone passed through similar situation:
In google play console, and after clicking on 'Grant access' in 'API Access' tab, you will need to select the user and add some permissions to the user (in my case I set it to admin, but I think it's larger than needed), make sure also to add the app/apps you are listening to.
If the issue is still running, just edit any of your products or just try creating new one, this step will clear the google cash and refresh permissions. (Check this question).

Authenticating Firebase Database with Google API via Firebase Functions

here's the task I have and the resources I'm following to try to get it done.
Ultimately what I want is for users to be able to take pictures with my app (made with Ionic) and then those pictures get sorted and end up on the company's Google Team Drive.
What I originally started with was uploading the images to Firebase Storage, and then I was told they must be accessible to Team Drive.
Some of the people taking pictures aren't part of the company's G Suite, so I was thinking it would be easier to just have the database itself authenticate with the Team Drive and upload from there.
Here is an example from github that shows the same thing I want, except it uploads from Firebase Database to Google Sheets:
https://github.com/firebase/functions-samples/tree/master/google-sheet-sync
My plan was to follow this guide exactly to get it working, and then figure out how I can change it for Storage -> Team Drive.
However in following the instructions in the readme (they're pretty old) I've come across an error and now I'm stuck.
For Step #7 in that link where it says to run $ firebase functions:config:set googleapi.client_id="<id>" and the rest of the command, I get in terminal:
Error: HTTP Error: 403, The caller does not have permission
What should be the steps I'm looking at to get this working? I am also unsure if my current implementation makes sense anymore. It wouldn't be a big deal to make everyone using the app sign-in with a Google account so that they can be a member of the Team Drive and just upload directly from the app to Drive. Would that still include the sort of safety behaviour like if the connection drops the file upload will resume independently?
The answer to my first question is to install googleapis and google-auth-library. Run the command in the actual /functions/ directory of the sample.
There were a few other errors created by old code, but they aren't in the scope of this question and I raised them in the github Issues sections.

box_auth() without localhost

I'm trying to use the boxr package to link my box account to R-Server.
I get as far in the box_auth() instructions as step 3 from the box pdf https://cran.r-project.org/web/packages/boxr/boxr.pdf
A window pops up and I authorise connection then I get the error 'Safari can't connect to the server'.
I have no knowledge of how apache or web development works so forgive my naivety, I've come to understand the problem is I don't have localhost set up on my Mac.
I'm unable to turn these features on because it requires admin rights and my company won't allow users to have this.
Is there something else I can put in the redirect_uri box apart from localhost that will allow this to authenticate?
Thanks
The issue i had was mostly that authenticating box through R-Server isn't supported. https://github.com/brendan-r/boxr/issues/23
To get around this I used my personal laptop to authenticate locally then uploaded the .Renviron and .boxr-oauth files to R server (which is the advice in the github post)
This was slightly tricky as R wasn't showing the .boxr-oauth file but I managed to copy it to a folder, zip the folder, then upload that to R-Server.
Now running the box_auth() function authenticates as it should.
As of v0.3.5 (November 2019) boxr has a new alternative authentication method designed for remote servers, box_auth_service(), that closes issue 23. It's slightly is different than the oAuth way, because it uses "Service" accounts as the actors instead of the "User" account. But the "Service" accounts are what's needed to maintain security within a organization, so we opted for that. Please open an issue on the repo if you run into any issues.

How to authenticate users of Shiny apps on shinyapps.io for Google Sheets (googlesheets)

I have a Shiny app making use of the googlesheets package which requires the user to authenticate for writing to Google Sheets (despite the Sheet being public and "published to the web"). This is done graphically in a browser, and works when the Shiny app is run locally. However, when deployed on shinyapps.io, the authentication call crashes the app and logs an error:
Warning: Error in : oauth_listener() needs an interactive environment.
So, what options are there? I'm thinking it would be a bad idea to upload my own .httr-oauth file or token to shinyapps.io... Any workarounds?
In case anyone else has a problem with this, the new {googlesheets4} provides a solution:
https://googlesheets4.tidyverse.org/articles/articles/auth.html
If you don’t need to access private Sheets, use gs4_deauth() to
indicate there is no need for a token. This puts googlesheets4 into a
de-authorized mode.
(an example script is also included)

Setting up rfigshare with API keys

I have recently installed the rfigshare package. In order to use it, I need to get figshare API keys to to use it properly. The documentation I found so far is obsolete (see here). Does anyone knows the procedure to follow?
From the package README:
The first time you use an rfigshare function, it will ask you to authenticate online. Just log in and click okay to authenticate rfigshare. R will allow you to cache your login credentials so that you won't be asked to authenticate again (even between R sessions), as long as you are using the same working directory in future.
So, just load the package using library("rfigshare") and call any function. You will be automatically prompted to login and store an OAuth credential locally, which will then be automatically used in subsequent function calls.

Resources