1

I would like to change the default permissions of a google sheets file to anyone with the link can read

weekly_fight <-
  googlesheets4::gs4_create(
    paste0(
      two_weeks_ago_monday,
      "-",
      two_weeks_ago_sunday,
      "/",
      last_monday,
      "-",
      last_sunday,
      "_Weekly Report Google Analytics My Site GA4|UA+Top SKU+COUPON"
    ),
    sheets = list(
      Weekly_Traffic_site1 = week_on_week_2,
      Weekly_Traffic_site2 = week_on_week_2_im,
      Ecommerce_Performances_site1_IT = top_products_sold_last_week_ua_site1_EN,
      Ecommerce_Performances_site2_IT = top_products_sold_last_week_ua_site2_EN,
      Coupon_site1 = count_coupon_site1,
      Coupon_site2 = count_coupon_site2
    )
  )


googlesheets4::gs4_browse(weekly_fight)

metadata <- googlesheets4::gs4_get(weekly_fight)

url_doc <- metadata$spreadsheet_url

I can read and browse the file as creator but when I send the link with the script via email with the gamilR package to my team they cannot access it as I need to manually update the permission in the file

Is there a way to change the default access to the file with the googlesheets4 package or the Drive API without manual intervention?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Andrea
  • 105
  • 10

1 Answers1

-1

First off to set permissions on a file you would need to go though the Google drive api. Changing the permissions is out of scope for the google sheets api.

This can be done with the permissions.create method in the google drive api.

Second anyone with link can read only works through the web UI you cant create that link via the any api drive or sheets.

enter image description here

You could set the file to public they anyone should be able to access it.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Thank you @daimto, If I understand correctly I can use the `permission.create` method with the ID of the sheet file and use the methods listed [here](https://developers.google.com/drive/api/v3/reference/permissions#resource) to parse the request – Andrea Aug 29 '22 at 19:34
  • 1
    yes just set it to public. then anyone will be able to access it. Just do a file.get on the file id and there should be a webview link that they will be able to open in a web browser window. Sorry i am not an R dev so i cant help with code. – Linda Lawton - DaImTo Aug 30 '22 at 06:46
  • 1
    thanks to your suggestion It works now, I have found a wrapper to facilitate this task within the [googledrive R](https://googledrive.tidyverse.org/index.html) package that has a function to change the permission of a file, you just need to provide it with a file ID or URL : `googledrive::drive_share_anyone(file = as_id(id))`. – Andrea Aug 30 '22 at 07:27