首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建始终与用户共享的文件和文件夹

创建始终与用户共享的文件和文件夹
EN

Stack Overflow用户
提问于 2019-09-03 19:50:35
回答 2查看 48关注 0票数 0

使用来自c#的Google Drive API和Spreadsheet Api。

如何将文件夹和文件(速查表)添加到文件夹,并确保它们始终对人类用户是共享和可见的?

我知道Google.Apis.Drive.Permission,但它有每日配额,并发送电子邮件,这似乎不是正确的解决方案。

我更希望能够在文件夹中工作,然后所有内容都应该始终对API和人类用户可见。

任何提示:)

EN

回答 2

Stack Overflow用户

发布于 2019-09-03 20:06:55

您可以使用Google drive api创建一个文件,然后添加对该文件的权限,以便与用户共享该文件。这就是你怎么做的,真的没有比这更好的方法了。为了使用户能够访问它,您必须授予他们对它的权限。

代码语言:javascript
复制
    /// <summary>
    /// Creates a permission for a file or Team Drive. 
    /// Documentation https://developers.google.com/drive/v3/reference/permissions/create
    /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
    /// </summary>
    /// <param name="service">Authenticated Drive service.</param>  
    /// <param name="fileId">The ID of the file or Team Drive.</param>
    /// <param name="body">A valid Drive v3 body.</param>
    /// <param name="optional">Optional paramaters.</param>
    /// <returns>PermissionResponse</returns>
    public static Permission Create(DriveService service, string fileId, Permission body, PermissionsCreateOptionalParms optional = null)
    {
        try
        {
            // Initial validation.
            if (service == null)
                throw new ArgumentNullException("service");
            if (body == null)
                throw new ArgumentNullException("body");
            if (fileId == null)
                throw new ArgumentNullException(fileId);

            // Building the initial request.
            var request = service.Permissions.Create(body, fileId);

            // Applying optional parameters to the request.                
            request = (PermissionsResource.CreateRequest)SampleHelpers.ApplyOptionalParms(request, optional);

            // Requesting data.
            return request.Execute();
        }
        catch (Exception ex)
        {
            throw new Exception("Request Permissions.Create failed.", ex);
        }
    }

从我的示例项目PermissionsSample.cs中摘录的代码

如果你在配额上有问题,那么你可以尝试去谷歌开发者控制台,让你的配额增加。注意:配额是基于请求的数量,而不是您正在发出的请求的类型。

票数 0
EN

Stack Overflow用户

发布于 2019-09-05 20:37:30

感谢您提供的有关权限的信息和示例!

我发现,如果你只是手动创建一个文件夹,这个文件夹是用google-drive-API-email-address共享的读/写的,然后确保这个文件夹中的所有东西都在运行,它的行为是想要的,所有文件对人和计算机都是可见的。

向Anders致以最好的问候

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57771183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档