【问题标题】:How I can copy google document and share access to email?如何复制谷歌文档并共享对电子邮件的访问权限?
【发布时间】:2020-05-30 17:50:54
【问题描述】:

google doc 上有一个模板。 我们想复制它并通过邮件提供访问权限。 也许有人知道如何实现这个?

【问题讨论】:

    标签: google-docs google-docs-api


    【解决方案1】:

    这个答案怎么样?

    很遗憾,Google Docs API 无法完成文件的复制和文件权限的修改。在这种情况下,需要使用 Drive API。实现目标的流程如下。

    1。 Google 文档文件的副本。

    在这种情况下,使用 Drive API v3 的“文件:复制”的方法。端点和示例请求正文如下。文件 ID 是模板 Google 文档文件的文件 ID。

    端点:

    POST https://www.googleapis.com/drive/v3/files/fileId/copy
    

    示例请求正文:

    {"name": "sample name"}
    

    curl 命令示例:

    curl --request POST \
      'https://www.googleapis.com/drive/v3/files/fileId/copy'
      --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
      --header 'Accept: application/json' \
      --header 'Content-Type: application/json' \
      --data '{"name":"sample name"}' \
      --compressed
    
    • 复制文件时,返回复制文件的文件ID。

    2。创建权限。

    在这种情况下,使用 Drive API v3 的“Permissions:create”方法。端点和示例请求正文如下。文件ID是复制文件的文件ID。

    端点:

    POST https://www.googleapis.com/drive/v3/files/fileId/permissions
    

    示例请求正文:

    {
      "role": "writer",
      "type": "user",
      "emailAddress": "###"
    }
    

    curl 命令示例:

    curl --request POST \
      'https://www.googleapis.com/drive/v3/files/fileId/permissions' \
      --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
      --header 'Accept: application/json' \
      --header 'Content-Type: application/json' \
      --data '{"role":"writer","type":"user","emailAddress":"###"}' \
      --compressed
    
    • 在这种情况下,电子邮件地址###的用户拥有该文件的作者权限。

    注意:

    • 在上述流程中,需要访问令牌。不幸的是,API 密钥不能用于这种情况。请注意这一点。
    • 如果您想使用 API 修改复制的 Google 文档,请使用 Google Docs API。

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 2014-11-26
      • 1970-01-01
      相关资源
      最近更新 更多