tidyverse / googlesheets4

Google Spreadsheets R API (reboot of the googlesheets package)
https://googlesheets4.tidyverse.org
Other
360 stars 53 forks source link

Permission difficulties through gs4_auth() and gs4_auth_configure() #310

Open JustGottaCAT opened 10 months ago

JustGottaCAT commented 10 months ago

My company has an internal Google domain and I'm attempting to read a Google spreadsheet from it. I keep getting permission errors when I try to use gs4_auth() or gs4_auth_configure().

If I use gs4_auth() I am taken to the authorization screen, choose "Yes", and then get this error: image

I allowed "Tidyverse API Packages" access via admin.google.com > Security > Access and data control > API Controls (for some reason there were 6 IDs). My company's domain is "Trusted and block-exempt". gs4_auth() still did not work.

I also tried generating an API key and client ID for the Google Sheets API and used that:

library(googlesheets4)
library(gargle)

google_client <- gargle_oauth_client_from_json(
path = 'path_to_Google_Sheets_client_ID_json_file.json',
name = 'Name of client ID in Google Cloud Console')

gs4_auth_configure(client = google_client, api_key = 'Google_Sheets_API_generated_key')

gs4_oauth_app()

<gargle_oauth_client>
name: Name of client ID in Google Cloud Console
id: Client ID in Google Cloud Console
secret: <REDACTED>
type: installed
redirect_uris: http://localhost

But I get a permission error when I actually try to read in a sheet:

read_sheet('sheet_ID')

Error in `gs4_get_impl_()`:
! Client error: (403) PERMISSION_DENIED
• Client does not have sufficient permission. This can happen because the OAuth token does not have the right scopes,
  the client doesn't have permission, or the API has not been enabled for the client project.
• The caller does not have permission

Eventually I would like this all done using encrypted service account credentials and would like to publish an Rmd with my code on our internal Posit Server, but I figure that is down the line if I can't even get the above to work.

jennybc commented 10 months ago

the API has not been enabled for the client project

It's hard to say what's going wrong, but currently my money is on this ☝️

Is the Sheets API definitely enabled for your oauth client?

dsteinberg20 commented 5 months ago

I'm having the exact same issue. How do I enable the sheets api in my oauth client?