Create/Update google drive permission in Go/ [Created spreadsheet using api but have no access to it]

Viewed 367

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!

1 Answers

Fixed the problem by setting supportAllDrives as true while creating the file. However this should already be deprecated but not on mine version.

Edit:

Looks like supportsAllDrives is not being deprecated anymore, at least for now. The deprecation note cannot be found anymore on the official docs, so it seems this is still supported.

Also, looking at this article, it looks like changes to shared drives have been postponed:

Editor's note: Due to current events the Google team has made the decision to avoid causing additional disruption during this uncertain time. As a result, we're postponing the proposed changes regarding the opt-in mechanism for shared drives indefinitely. Shared drives and files within a shared drive will only be returned when requests set the relevant opt-in parameters.

Related