Google Apps脚本TeamDrive DriveApp.searchFolders和DriveApp.searchFiles不返回任何结果 [英] Google Apps Script TeamDrive DriveApp.searchFolders and DriveApp.searchFiles does not return any results

查看:63
本文介绍了Google Apps脚本TeamDrive DriveApp.searchFolders和DriveApp.searchFiles不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 Google Apps脚本代码,用于在TeamDrive上搜索文件和文件夹.

I have some Google Apps script code that searchs for files and folders on TeamDrive.

我遇到的问题是,如果文件或文件夹是由我的同事创建的,则在我运行脚本时找不到该文件.如果我创建了一个文件,并且我的同事运行了该脚本,则即使我们俩都有权查看,编辑并可以看到云端硬盘中的文件和文件夹,该脚本也找不到该文件.如果我们中的一个人编辑另一个人制作的文件,则在搜索中可以看到该文件.

The issue I am having is that if a file or folder is created by my colleague, when I run my script it can't find the file. If I create a file, and my colleague runs the script, the script can't find the file even though we both have access to view, edit and can see the files and folders in Drive. If one of us edits the file made by the other person, then it becomes visible from the search.

在进行一些Android开发时,我遇到了Drive REST API的类似问题.在Android中,当调用files().list()时,我花了一段时间才发现必须设置以下内容才能使搜索每次成功.

I ran into a similar problem with the Drive REST api when doing some android development. In Android when calling files().list(), It took my a while to find out that I had to set the following in order for my search to be successfull every single time.

  1. .setSupportsTeamDrives(true)
  2. .setIncludeTeamDriveItems(true)
  3. .setCorpora("teamDrive")
  4. .setTeamDriveId(myFolder.getTeamDriveId())

我认为我的应用程序脚本代码遇到了同样的问题.

I assume I am running into the same issue with my apps script code.

//Create the N Google docs files
function CreateNFiles(){
  var spreadsheet = SpreadsheetApp.getActive();
  var Nmain = spreadsheet.getSheetByName("Nmain")
  var spreadsheetId = spreadsheet.getId();
  var pdfDir = "Form Data";
  var TemplatesFolder = null;

  //Check and see if there is a 'Form Data' folder
  var NFolderId = null;
  var RFolderId = DriveApp.getFileById(spreadsheetId).getParents().next().getId();
  var files = DriveApp.searchFolders('parents="'+RFolderId+'" and trashed=false');
  while (files.hasNext()) {
    var myfile = files.next();
    if(myfile.getName() == pdfDir){
      NOFolderId = myfile.getId();
    }
  }

https://developers.google.com/apps-script/reference/drive/drive-app#searchFiles(String)

这是指

https://developers.google.com/drive/api/v3/search-parameters#examples_for_teamdriveslist

所以我有可能使用

corpora ="teamDrive"

corpora="teamDrive"

是否可以设置setSupportsTeamDrives?和setIncludeTeamDriveItems?和setTeamDriveId?在Google Apps脚本中

is there a way to setSupportsTeamDrives? and setIncludeTeamDriveItems? and setTeamDriveId? in google apps scripts

推荐答案

查找团队驱动器中的文件和文件夹

为满足自己的需要,我在努力着几个功能.它们仍在进行中,但是一个可以在团队驱动器文件夹中文件夹,另一个可以在团队驱动器文件夹中查找项目.Logger.log设置为显示项目编号,标题,ID和mimeType.

Finding Files and Folders in a Team Drive

Here's a couple of functions I've been working on for my own needs. They're still a work in progress but one can file folders within a team drive folder and another can find items within a team drive folder. The Logger.log is setup to display item number, title, id, and mimeType.

此文件可以找到项目(文件或文件夹).您可以按类型区分它们.

This one finds Items (either files or folders). You can tell them apart by their types.

function findItemsInTeamDriveFolder(teamDriveId,folderId){
  var teamDriveId=teamDriveId || '0AFN5OZjg48ZvUk9PVA';
  var folderId=folderId || '1LK76CVE71fLputdFAN-zuL-HdRFDWBGv';
  var options={
    "corpora":"teamDrive",
    "includeTeamDriveItems":true,
    "orderBy":"folder",
    "q":Utilities.formatString('\'%s\' in parents',folderId),
    "supportsTeamDrives":true,
    "teamDriveId":teamDriveId
    };
  var files=Drive.Files.list(options);
  var data=JSON.parse(files);
  for(var i=0;i<data.items.length;i++){
    Logger.log('\nItem: %s - Title: %s - Id: %s - Type:%s - Trashed: %s\n',i+1,data.items[i].title,data.items[i].id,data.items[i].mimeType,data.items[i].explicitlyTrashed?'true':'false'); 
  }
}

这只是在一个文件夹中找到文件夹.它不是可重入的,这只是一个一级协议,但是目前我只需要这些.

This one just finds folders in a folder. It's not reentrant it's a one level deal but currently that's all I need.

function findFoldersInATeamDriveFolder(teamDriveId,folderId){
  var teamDriveId=teamDriveId || '0AAc6_2qyI7C0Uk9PVA';
  var folderId=folderId || '1HenWOXTSCg96iAvA0ZkgEA9EGKlch4fz';
  var optionalArgs={
    "corpora":"teamDrive",
    "includeTeamDriveItems":true,
    "orderBy":"folder",
    "q":Utilities.formatString('\'%s\' in parents and mimeType = \'application/vnd.google-apps.folder\'',folderId),
    "supportsTeamDrives":true,
    "teamDriveId":teamDriveId
  }
  var list=Drive.Files.list(optionalArgs)
  var data=JSON.parse(list);
  for(var i=0;i<data.items.length;i++){
    Logger.log('\nItem: %s - Title: %s - Id: %s - Type: %s - Trashed;%s\n',i+1,data.items[i].title,data.items[i].id,data.items[i].mimeType,data.items[i].explicitlyTrashed?'true':'false'); 
    findItemsInTeamDriveFolder(teamDriveId,data.items[i].id)
  }
}

我认为它们可能会有所帮助.

I thought that they might be helpful.

这篇关于Google Apps脚本TeamDrive DriveApp.searchFolders和DriveApp.searchFiles不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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