【问题标题】:Extract image files from Google Cloud Storage using R使用 R 从 Google Cloud Storage 中提取图像文件
【发布时间】:2021-02-04 12:53:06
【问题描述】:

我设法生成了密钥和令牌,以便能够从 r 控制台中访问谷歌云存储文件。

但是,在执行下面的代码时,我遇到了以下错误 -

Error: $installed not found in JSON - have you downloaded the correct JSON file? 
           (Service account client > Desktop, not Service Account Keys)

虽然代码已从以前的 SO 帖子中解决/提供,但该错误对我来说仍然很神秘。

-- 所以在下面发帖

Accessing files from Google cloud storage in RStudio

-- 完整代码如下

rm(list = ls(all.names = TRUE))
options(java.parameters = "-Xmx8000m")

library(googleCloudStorageR)
library(googleAuthR)
library(jsonlite)


# for working in google cloud storage

GCS_AUTH_FILE = "serviceaccount.json"  
GAR_CLIENT_WEB_JSON = "Oauthclient.json"
# fromJSON(GCS_AUTH_FILE)
# fromJSON(GAR_CLIENT_WEB_JSON)

gar_auth_service(GCS_AUTH_FILE)

#set the scope
gar_set_client(scopes = c("https://www.googleapis.com/auth/devstorage.read_write",
                          "https://www.googleapis.com/auth/cloud-platform"), json = GAR_CLIENT_WEB_JSON
)    

【问题讨论】:

    标签: r google-cloud-storage


    【解决方案1】:

    您似乎没有使用正确的 JSON 文件。我发现这个Github post 提到了如何正确配置它。

    这些是步骤:

    1. 启用 Google 云存储 API
    2. 凭据 >> 创建凭据 >> OAuth 客户端 ID >> 其他
    3. 将 JSON 文件保存为类似 my-ClientID-credentials.json 的文件 凭据>>创建凭据>>服务帐户密钥
    4. 将 JSON 文件另存为 my-service-account-credentials.json 之类的文件

    这是帖子中提到的代码

    # Google cloud storage
    
    # Setup
    library(googleCloudStorageR)
    options(googleAuthR.scopes.selected = "https://www.googleapis.com/auth/devstorage.full_control")
    
    # Authenticate ClientID
    googleAuthR::gar_set_client("path/to/my-ClientID-credentials.json")
    
    # Authenticate service account
    Sys.setenv("GCS_AUTH_FILE" = "full/path/to/my-service-account-credentials.json")
    googleCloudStorageR::gcs_auth()
    
    ## Get bucket info
    gcs_list_buckets(projectId = "my-project")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 2015-04-09
      • 2018-07-17
      • 2013-08-22
      相关资源
      最近更新 更多