客户端没有足够的权限

Dan*_*low 10 r google-sheets-api googlesheets4

我目前正在跑步

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))
Run Code Online (Sandbox Code Playgroud)

并得到以下输出。

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
Run Code Online (Sandbox Code Playgroud)

我不确定问题是否在于它迫使我使用第一封电子邮件?可以改成第二个token吗?但我也很困惑为什么我不再被要求进入我的谷歌帐户来验证事物?

任何想法为什么会发生这种情况?我是 API 新手。

Vis*_*rma 8

这可能是因为当您使用 登录时gs_auth,您一定选择了错误的权限。要重新分配您的权限,请首先使用解除身份验证,gs_deauth()然后使用gs_auth()并在下一个选项中输入0重新Selection: 初始化您对 Google 帐户的访问权限。确保在分配权限时在浏览器窗口中选中用于读取、写入电子表格的复选框。

如果您无法做到,请评论。

继续编码!


Del*_*eet 8

对我来说,解决方案是:

googlesheets4::gs4_deauth()
googlesheets4::gs4_auth()
Run Code Online (Sandbox Code Playgroud)

然后,当您拨打第二个电话时,不要按 1 选择您的电子邮件,而是按 0 获取新令牌:

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
Run Code Online (Sandbox Code Playgroud)


小智 2

你可以尝试用这个

图书馆(googlesheets4)

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

您应该在凭据中创建一个 api 密钥 https://console.cloud.google.com/apis/credentials

我等待它可以帮助你