I'm trying to create a spreadsheet using google drive api with the following code, but I have no access to it.
[update: the file doesn't seem to be in the drive I specified here, anyone know why is that happening?]
[update: added parents in the field, but have 404 error, says file not found, thanks in advance if anyone knows the reason.]
func (dr *driveService) CreateFile(driveId string, fileName string, parents []string) (*drive.File, error) {
file := &drive.File{
DriveId: driveId,
Name: fileName,
MimeType: mimeTypeSpreadsheet,
Parents: parents,
}
file, err := dr.googleDriveService.Files.Create(file).Do()
return file, err
}
So i tried to create/update the permissions using this code, but this error occurs Error 403: The resource body includes fields which are not directly writable., fieldNotWritable
func (dr *driveService) CreatePermission(fileId string, permissionType string, permissionRole string) error {
permissionToBeCreated := &drive.Permission{
Type: permissionType,
Role: permissionRole,
}
filePermission, err := dr.googleDriveService.Permissions.Create(fileId, permissionToBeCreated).Do()
if err != nil {
fmt.Printf("An error occurred creating permission for file: %v\n", err)
return err
}
_, err = dr.googleDriveService.Permissions.Update(fileId, filePermission.Id,filePermission).Do()
if err != nil {
fmt.Printf("An error occurred: %v\n", err)
return err
}
return nil
}
So tried to remove the update part in the second function, but there's nil for the permissions of the file.
So, does someone have any idea how to fix this? or in general how can I create a spreadsheet that everyone has the link can access it?
Thanks!