r - 通过 R Studio Server 使用 BigQuery 在 Google Compute Engine 上验证服务帐户

标签 r google-bigquery google-compute-engine

我希望从安装在 Google Compute Engine 上的 R Studio 调用 BigQuery。

我在实例上安装了 bq python 工具,我希望使用它的服务帐户和 system() 让 R 调用 bq 命令行工具,从而获取数据。

但是,我遇到了身份验证问题,它要求提供浏览器 key 。我很确定由于服务帐户而无需获取 key ,但我不知道如何使用 R 构建身份验证(它在 RStudio 上运行,因此会有多个用户)

我可以获得这样的身份验证 token :

library(RCurl)
library(RJSONIO)
metadata <-  getURL('http://metadata/computeMetadata/v1beta1/instance/service-accounts/default/token')
tokendata <- fromJSON(metadata)

tokendata$$access_token

但是我该如何使用它来生成 .bigqueryrc token ?缺少它会触发身份验证尝试。

这工作正常:

system('/usr/local/bin/bq')

显示 bq 安装正常。

但是当我尝试类似的东西时:

   system('/usr/local/bin/bq ls')

我明白了:

Welcome to BigQuery! This script will walk you through the process of initializing your .bigqueryrc configuration file.

First, we need to set up your credentials if they do not already exist.


******************************************************************
** No OAuth2 credentials found, beginning authorization process **
******************************************************************

Go to the following link in your browser:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbigquery&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&client_id=XXXXXXXX.apps.googleusercontent.com&access_type=offline

Enter verification code: You have encountered a bug in the BigQuery CLI. Google engineers monitor and answer questions on Stack Overflow, with the tag google-bigquery:     http://stackoverflow.com/questions/ask?tags=google-bigquery

etc.

编辑:

我已经设法从 RStudio system() 命令中获得 bq 功能,通过以用户身份使用 RStudio 登录到终端跳过身份验证,通过浏览器登录在那里进行身份验证,然后重新登录到 RStudio 并调用系统("bq ls") 等..所以这足以让我继续:)

但是,如果 BQ 可以在 RStudio 本身中进行身份验证,我仍然会更喜欢它,因为许多用户可能会登录,我需要通过终端为所有这些用户进行身份验证。从服务帐户文档,以及我可以获得身份验证 token 的事实,都暗示这更容易。

最佳答案

目前,在从 GCE 中的脚本调用 bq 之前,您需要从命令行运行“bq init”来设置您的凭据。但是,bq 的下一个版本将通过新的 --use_gce_service_account 标志支持 GCE 服务帐户。

关于r - 通过 R Studio Server 使用 BigQuery 在 Google Compute Engine 上验证服务帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16695475/

相关文章:

r - 尝试向 choroplethr 县 map 添加边框颜色时找不到对象 'value'

r - 使用 dplyr::mutate 计算到数据点的地理距离

r - 变异多个变量以创建多个新变量

google-bigquery - 嗨,BigQuery是否支持实例化 View ?

amazon-web-services - 使用 Terraform 在新创建的虚拟机上创建 Docker 容器

google-cloud-platform - 将 Google Container Engine 与 GCP 免费套餐结合使用

r - 将 textGrob 转换为 imageGrob/rasterGrob?

google-bigquery - 使用自动检测加载数据时出现 "Invalid schema update"错误

sql - 如何按同一查询中生成的列进行过滤?

google-cloud-platform - Google Cloud Monitoring 组包含已短暂关闭的实例