AofWessex
AofWessex

Reputation: 157

Extract image files from Google Cloud Storage using R

I managed to generate keys and tokens to be able to access google cloud storage files from within the r console.

However, upon executing the code below, i run into below error -

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

While the code has been addressed/provided from previous SO post, the error is still enigmatic to me.

-- SO post below

Accessing files from Google cloud storage in RStudio

-- full code below

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
)    

Upvotes: 0

Views: 268

Answers (1)

Andie Vanille
Andie Vanille

Reputation: 820

It seems that you are not using the correct JSON file. I found this Github post that mentions how to configure this correctly.

These are the steps:

  1. Enable Google Cloud Storage API
  2. Credentials >> Create Credentials >> OAuth Client ID >> Other
  3. Save the JSON file as something like my-ClientID-credentials.json Credentials >> Create Credentials >> Service Account Key
  4. Save the JSON file as something like my-service-account-credentials.json

This is the code mentioned in the post

# 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")

Upvotes: 2

Related Questions