简体   繁体   中英

How to check share setting of gsheet by gspread

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

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM