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

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

问题描述

我正在尝试使用Google Apps脚本在共享驱动器中创建新文件,以便其他使用共享驱动器的人也可以访问该文件. 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天全站免登陆