在Go/中创建/更新Google驱动器权限[使用api创建电子表格,但无权访问它] [英] Create/Update google drive permission in Go/ [Created spreadsheet using api but have no access to it]

查看:68
本文介绍了在Go/中创建/更新Google驱动器权限[使用api创建电子表格,但无权访问它]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有以下代码的Google Drive API创建电子表格,但是我无权访问它.

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?]

[更新:在该字段中添加了父母,但出现404错误,找不到文件,如果有人知道原因,请提前感谢.]

[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
}

因此,我尝试使用此代码创建/更新权限,但发生此错误错误403:资源正文包含不可直接写的字段.fieldNotWritable

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
}

因此尝试删除第二个功能中的 update 部分,但文件权限为 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?

谢谢!

推荐答案

通过在创建文件时将 supportAllDrives 设置为true来解决此问题.但是,应该已经不建议使用此功能,但我的版本上不应使用此功能.

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

修改:

至少现在不推荐使用 supportsAllDrives 之类的东西.不再在官方文档中找到弃用说明,因此似乎仍支持该弃用说明.

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:

编者注:由于当前的事件,Google团队已决定避免在此不确定的时间内造成其他干扰.因此,我们将无限期推迟有关共享驱动器选择机制的建议更改.共享驱动器和共享驱动器中的文件仅在请求设置了相关的启用参数时才返回.

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.

这篇关于在Go/中创建/更新Google驱动器权限[使用api创建电子表格,但无权访问它]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆