使用REST Apps脚本获取共享驱动器时找不到Google共享驱动器

时间:2020-05-22 14:45:25

标签: rest google-apps-script google-drive-api

我想使用REST获取共享驱动器,如果我在API页面上尝试了API,它可以正常工作并收到200响应,但是当我在Apps脚本上运行代码时,它说,找不到共享驱动器。

{error = {errors = [{locationType = parameter,reason = notFound, domain = global,消息=找不到共享驱动器:DriveID, location = driveId}],代码= 404.0,消息=找不到共享驱动器: DriveID}}

这是我的代码:

function getDrives(){
  var service = getDriveService();
 //get Drives
  service.reset()

  if(service.hasAccess){

    var urlDrive = 'https://www.googleapis.com/drive/v3/drives/myDriveId?useDomainAdminAccess=true&key=myAPIKey HTTP/1.1';
    var outputDrives = UrlFetchApp.fetch(urlDrive, {
    method: 'get',
    headers: { 'Authorization': 'Bearer ' + service.getAccessToken() },
    contentType: 'application/json',
    muteHttpExceptions: true
  }).getContentText();  

  var responseDrives = JSON.parse(outputDrives);
  Logger.log(responseDrives)
  }

  //end of getting drives 
}

我尝试了所有可能的解决方案,但没有任何效果。希望有人可以帮助我。预先感谢。

1 个答案:

答案 0 :(得分:0)

尝试添加:supportsAllDrives:是。 (我在节点API中使用它来访问共享驱动器)

var urlDrive = 'https://www.googleapis.com/drive/v3/drives/myDriveId?useDomainAdminAccess=true&key=myAPIKey HTTP/1.1';
    var outputDrives = UrlFetchApp.fetch(urlDrive, {
    method: 'get',
    headers: { 'Authorization': 'Bearer ' + service.getAccessToken() },
    contentType: 'application/json',
    muteHttpExceptions: true,
    supportsAllDrives: true,
    includeItemsFromAllDrives: true
  }).getContentText();  

希望它能起作用。