rgoogle-drive-apigoogle-sheets-apigooglesheets4

Change the Default Access Permission of a Google Sheets made with googlesheets4 with R


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?


Solution

  • 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.