php editor Zimo is here to tell you that to add collaborators to Google Sheet, there are two methods to choose from: using the Golang client library or REST API. Using the Golang client library, you can add collaborators by calling the Google Sheets API. The method of using the REST API is to send an HTTP request to the Google Sheets API. No matter which method you choose, you can easily add collaborators to your Google Sheet to share and edit the sheet with others.
I can create a new spreadsheet using the gsheets client library, the next step is to add the editor to the newly created worksheet so that it is accessible to users of the application This worksheet
The following is the code to create the worksheet:
ctx := context.background() srv, err := gsheets.newservice(ctx) if err != nil { log.printf("unable to retrieve sheets client: %v", err) } sp := &gsheets.spreadsheet{ properties: &gsheets.spreadsheetproperties{ title: groupname, }, } spreadsheet, err := srv.spreadsheets.create(sp).do() if err != nil { return nil, err }
I searched the golang client library documentation and rest api documentation but couldn't find anything related to adding collaborators
I expect to have some request objects that allow me to add collaborators using their emails and roles:
req := gsheets.Request{ AddCollaborator: &gsheets.AddCollaboratorRequest{ Email: "[email protected]", Role: "editor", }, } busr := &gsheets.BatchUpdateSpreadsheetRequest{ Requests: []*gsheets.Request{&req}, } res, err := srv.Spreadsheets.BatchUpdate(spreadsheetId, busr).Do()
Or at least I expected there to be an api endpoint where I could achieve the same result
I'm also curious if there is a way to create this new spreadsheet as read-only public? This would at least allow me to continue development
The editor can be added using the google.golang.org/api/sheets/v4
library.
You can simply create a spreadsheet:
func (r *spreadsheetsservice) create(spreadsheet *spreadsheet) *spreadsheetscreatecall
and add an editor with editor type:
type Editors struct { ... // Users: The email addresses of users with edit access to the protected // range. Users []string `json:"users,omitempty"` ... }
See library documentation for more details.
The above is the detailed content of Is there a way to add collaborators to Google Sheet using Golang client library or REST API?. For more information, please follow other related articles on the PHP Chinese website!