Home > Net >  How to check share setting of gsheet by gspread
How to check share setting of gsheet by gspread

Time:01-23

I want to check owner share settings of gsheets by using gsperad as below.

img

Now I can get the share data by use list_permissions(file_id) but I need more information about owner share settings by get True of False of Editors can change permissions and share and Viewers and commenters can see the option to download, print, and copy.

Thank you for your support

CodePudding user response:

In order to manage "Viewers and commenters can see the option to download, print, and copy", viewersCanCopyContent is used.

In order to manage "Editors can change permissions and share", writersCanShare is used.

From this situation, in order to achieve your goal of I want to check owner share settings of gsheets by using gsperad as below., it is required to confirm the values of viewersCanCopyContent and writersCanShare of the file.

When this is reflected in a sample script for gspread, how about the following sample script?

Sample script:

import gspread
from googleapiclient.discovery import build

spreadsheet_id = "###" # Please set your Spreadsheet ID.
client = gspread.oauth(###) # Please use your client of gspread.

service = build("drive", "v3", credentials=client.auth)
res = service.files().get(fileId=spreadsheet_id, fields="viewersCanCopyContent,writersCanShare").execute()
print(res)
  • When this script is run, you can see the value of {'viewersCanCopyContent': True, 'writersCanShare': True}. Here, when viewersCanCopyContent is True, "Viewers and commenters can see the option to download, print, and copy" is checked. When writersCanShare is True, "Editors can change permissions and share" is checked.

  • If you want to manage those values, please use "Files: update" method of Drive API.

Note:

  • In this sample script, it supposes that you have already been able to get and put values to Google Spreadsheet using gspread for python. Please be careful about this.

  • About from googleapiclient.discovery import build, please check google-api-python-client.

References:

  • Related