8

I am currently running

library(googlesheets4)
sheets_auth()

dat=read_sheet("https://docs.google.com/spreadsheets/d/1R9XuH9Wej-p6HdkFGV2IsHuCmA9w0s7M3-jzE3S-Qrs/edit#gid=950673024", sheet="Summary", range=cell_rows(1:777))

and getting the following output.

Suitable tokens found in the cache, associated with these emails:
  * dcallow@umd.edu
  * ddcc2442@gmail.com
The first will be used.
Using an auto-discovered, cached token.
To suppress this message, modify your code or options to clearly consent to the use of a cached token.
See gargle's "Non-interactive auth" vignette for more details:
https://gargle.r-lib.org/articles/non-interactive-auth.html
The googlesheets4 package is using a cached token for dcallow@umd.edu.
> 
> dat=read_sheet("https://docs.google.com/spreadsheets/d/1R9XuH9Wej-p6HdkFGV2IsHuCmA9w0s7M3-jzE3S-Qrs/edit#gid=950673024", sheet="Summary", range=cell_rows(1:777))
Error: 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

I am unsure if the issue is that it is forcing me to use the first email? Is it possible to change to the second token? But I am also confused about why I am no longer being asked to go into my google account to authenticate things?

Any ideas why this might be occurring? I am new to API's.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Daniel Callow
  • 101
  • 1
  • 6
  • Have you tried logging out of all sessions and logging in only as the second email? Also, you don't need to authenticate a second time if you have already obtained the token for your project and haven't changed the scopes, so this is normal. – Rafa Guillermo Apr 22 '20 at 08:19

4 Answers4

8

This could be because while you logged in using gs_auth, you must have selected the wrong permissions. To re assign your permissions, first deauth using gs_deauth() and then use gs_auth() and in the next option, enter 0 in the Selection: to re-initialize your accesses to google account. Make sure in the browser window while assigning the permissions, you select the checkbox to read, write the spreadsheets.

Please comment if you're unable to do it.

Keep Coding!

Vishal Sharma
  • 289
  • 2
  • 10
6

For me the solution was:

googlesheets4::gs4_deauth()
googlesheets4::gs4_auth()

Then when you call the second one, DO NOT press 1 to select your email, instead press 0 to fetch a new token:

The googlesheets4 package is requesting access to your Google account.
Select a pre-authorised account or enter '0' to obtain a new token.
Press Esc/Ctrl + C to cancel.

1: your.email@gmail.com
CoderGuy123
  • 6,219
  • 5
  • 59
  • 89
2

you can try with this

library(googlesheets4)

gs4_auth_configure(api_key = "A..............bMGBUA")

you should create a api key in credentials https://console.cloud.google.com/apis/credentials

i wait that it can help you

-1

You can also 'Set GoogleSheet link to 'Anyone on the internet with this link can view' under the 'Share' button on the googlesheet page. Then:

googlesheets4::gs4_deauth()
CellROSConc <- read_sheet("https://docs.google.com/spreadsheets/d/1bxTIKTNfv-n3Y-JMJCOlt14Ec3e4tSdBQZg-HiuypOY/edit?usp=sharing")
Karl
  • 1,074
  • 8
  • 25
user73522
  • 97
  • 3
  • This seesm a very unsatisfactory insecure approach to solving the original problem. – Peter Ellis Feb 11 '22 at 22:00
  • 1
    it may be unsatisfactory and insecure, but after half an hour of trying to get authorization to work, unsuccessfully, this was the only thing that allowed me to read the file. since the data i am working with is in no way sensitive or private, it works well. what is interesting was that as long as i was authorized, i could not read the data. i could only do so after gs4_deauth(), even though i was the owner of the account. i assume there was some flaw in how i authorized, but, after long reading on the tidyverse site and here, i was unable to solve the problem...quite frustrating – dave adelson Aug 11 '22 at 18:29