首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R将令牌作为参数传递给read_sheet的googlesheets4

R将令牌作为参数传递给read_sheet的googlesheets4
EN

Stack Overflow用户
提问于 2020-10-29 18:14:26
回答 1查看 208关注 0票数 0

我只有在一张纸已经被授权的情况下才能阅读它,

如果不是,后续的每一行代码都会被忽略,因为代码执行一直在请求令牌。有没有办法将令牌索引传递到read_sheet命令中,或者是否有某种方法可以预先授权访问?

代码语言:javascript
复制
   > aa <- read_sheet('https://docs.google.com/spreadsheets/d....', sheet='Akinesia', range="AC:AH")
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 abort.

1: chris.elliott@.....

Selection: 
Enter an item from the menu, or 0 to exit
Selection: 
Enter an item from the menu, or 0 to exit
Selection: 
Enter an item from the menu, or 0 to exit
Selection: aaX <- aa  %>% filter_all(any_vars(!is.na(.)))
Enter an item from the menu, or 0 to exit
Selection: akns <- aaX %>% pivot_longer(-genotype, names_to = "day", values_to = "nonresp")
Enter an item from the menu, or 0 to exit
EN

回答 1

Stack Overflow用户

发布于 2020-10-29 18:19:48

您需要进行auth调用,该调用提供不同的身份验证方法:

默认身份验证

尝试不带参数或使用与Google帐户关联的电子邮件地址的默认呼叫:

代码语言:javascript
复制
googlesheets4::gs4_auth(email = "chris.elliott@...")

服务帐户

您还可以传递与服务帐户关联的令牌文件:

代码语言:javascript
复制
googlesheets4::gs4_auth(path = "access_token.json")

jsonlite::fromJSON()的txt参数所支持的一种格式(通常是文件路径或

字符串)。

含口令牌

googlesheets4使用gargle包,因此您也应该能够像这样获得令牌:

代码语言:javascript
复制
library(gargle)
token <- token_fetch()
googlesheets4::gs4_auth(token = token)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64589029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档