使用 DriveApp 访问共享驱动器 [英] Accessing shared drive with DriveApp

查看:24
本文介绍了使用 DriveApp 访问共享驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 google 应用程序脚本在共享驱动器中创建一个新文件,以便使用共享驱动器的其他人也可以访问该文件.DriveApp 上是否有允许我这样做的方法?

I am trying to create a new file in a shared drive using google apps script so that other people using the shared drive can also access the file. Is there a method on DriveApp that allows me to do that?

我曾尝试使用 DriveApp.getFoldersByName 但这仅适用于我私人驱动器中的根文件夹.

I have tried using DriveApp.getFoldersByName but this is for the root folder in my private drive only.

推荐答案

您需要使用 高级云端硬盘服务基于 云端硬盘 API

方法 Drive.Drives.insert 允许您指定驱动器 ID.

You need to use the Advanced Drive Service based on the Drive API

The method Drive.Drives.insert allows you to specify the Drive Id.

请记住,对于共享驱动器,您需要指定附加参数 supportsAllDrives: true.此外,您需要在使用前启用高级云端硬盘服务.

Keep in mind that for shared drives, you need to specify the additional parameter supportsAllDrives: true. Also, you need to enable the Advanced Drive Service before using.

示例:

function myFunction() {  
  var optionalArgs={supportsAllDrives: true};
  var resource = {
    title: 'mySharedFile',
    mimeType: 'application/pdf',
    parents:[{
      "id": "ID OF THE SHARED DRIVE"
    }]
  }  
  Drive.Files.insert(resource, null, optionalArgs)
}

这篇关于使用 DriveApp 访问共享驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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