【问题标题】:Authentication for Bigquery using bigrquery from an R Markdown document使用 R Markdown 文档中的 bigrquery 对 Bigquery 进行身份验证
【发布时间】:2020-05-25 18:28:55
【问题描述】:

我在使用 bigrquery 从我编写的 R Markdown 文档中连接到 GCP 服务帐户时遇到问题。当我从控制台尝试时,身份验证工作正常。两者都有

library(bigrquery)
bq_auth()

library(bigrquery)
bq_auth(email="my-service-account-email@myproject.iam.gserviceaccount.com")

启动带有对话框的浏览器,让我可以按预期使用指定的帐户进行选择和验证。但是在 R Markdown 中,任何尝试都像

options("httr_oob_default" = TRUE)
bq_auth(email="my-service-account-email@myproject.iam.gserviceaccount.com")

甚至像这样使用完整列表

bq_auth(
  email = "my-service-account-email@myproject.iam.gserviceaccount.com",
  path = NULL,
  scopes = c("https://www.googleapis.com/auth/bigquery"),
  cache = gargle::gargle_oauth_cache(),
  use_oob = gargle::gargle_oob_default(),
  token = NULL
)

导致错误

Error: Can't get Google credentials.
Are you running bigrquery in a non-interactive session? Consider:
  * Call `bq_auth()` directly with all necessary specifics.

谁能看到我错过了什么?提前致谢。

【问题讨论】:

    标签: r authentication google-bigquery bigrquery


    【解决方案1】:

    您可以下载您的 Google Cloud 服务帐户的 JSON 文件,然后将其用作“bq_auth”函数可以识别的路径。步骤如下:

    1. 谷歌云控制台 (console.cloud.google.com)
    2. 导航菜单
    3. IAM 和管理服务
    4. 帐户
    5. 创建服务帐户(创建一个)
    6. 创建Key,并保存到“/path/to/jsonfilename.json”
    7. 在您的 R Markdown 代码中进行身份验证:bigrquery::bq_auth(path = "/path/to/jsonfilename.json")

    注意:您需要确保将服务帐号设置为有权访问 BigQuery。我将我的设置为“BigQuery Admin”并且它有效,但这可能过于宽泛

    从 Elaine See 在媒体上的帖子中借用了这个答案:https://medium.com/@elaine.yl.see/easiest-way-to-use-bigquery-in-r-8af466cd55ca

    【讨论】:

    • 另外,请参阅此处的“身份验证和授权”部分:cran.r-project.org/web/packages/bigrquery/readme/README.html
    • 感谢布伦特!可以验证此答案是否有效。我很久以前就争论过,但忘记了问题就在这里。欣赏清晰的表达。
    • 现在互联网将有这些说明以供将来使用!很高兴为您提供帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2022-09-23
    • 2017-03-11
    • 2021-04-10
    • 1970-01-01
    • 2015-07-23
    相关资源
    最近更新 更多