library("googledrive")
library("googlesheets")
library("dplyr")
library("readr")

Motivation

Push a table into a Sheet.

Try to read it as another user Assume you even have the key. You will fail.

Now, as the user who owns the Sheet, publish it.

Now, as the other user, try again to read it via googlesheets. You should succeed.

Push a file into a Sheet

drive_auth("drive-token.rds")
file <- drive_upload(
  R.home('doc/BioC_mirrors.csv'),
  type = "spreadsheet"
)

Check publication status (should be FALSE)

drive_show_publish(file)

get URL

url <- drive_share_link(file)
url

it's published, not shared

file
key <- file$id

switch to different account

gs_auth("sheets-token.rds")

this shouldn't work

try(gs_url(url, visibility = "private", lookup = FALSE))
geterrmessage()

publish it on Drive

file <- drive_publish(file)
drive_show_publish(file)

try again!

gs_url(url, lookup  = FALSE)

check again that the access - it is not shared, but it is published.

promote(file, "shared")

clean up

drive_rm(file)

Now let's try shared but not published

file <- drive_upload(
  R.home('doc/BioC_mirrors.csv'),
  type = "spreadsheet"
)
file <- drive_share(file, role = "reader", type = "anyone")
url <- drive_share_link(file)
url

this should work!

gs_url(url, visibility = "private", lookup = FALSE)

It is not published, but it is shared.

file <- drive_show_publish(file)


tidyverse/googledrive documentation built on Jan. 14, 2024, 3:44 a.m.