简体   繁体   English

使用Google脚本将共享文件移到“我的云端硬盘”中吗?

[英]Move a shared file into My Drive using Google Script?

I am writing a script for my company that will automatically make a copy of a file in my own drive, then transfer ownership of the copy to a list of users from a spreadsheet. 我正在为公司编写脚本,该脚本将自动在自己的驱动器中创建文件的副本,然后将该副本的所有权从电子表格转移到用户列表中。 The script works completely except for that the file is created in the user's "All Files" and doesn't show up in their My Drive! 该脚本完全可以运行,除了该文件是在用户的“所有文件”中创建的,并且不会显示在其“我的云端硬盘”中! Transferring ownership is not the problem I'm having, the problem is the location of the transferred file in the new owner's Drive. 转移所有权不是我遇到的问题,问题在于转移的文件在新所有者的云端硬盘中的位置。

I've tried sending it to their root folder but that didn't work, I'm not sure why? 我曾尝试将其发送到他们的根文件夹,但这没有用,我不确定为什么吗? It sends it to My Drive for me, but it is copied into a folder that is already in My Drive for me (because I copy the file from a file that is in a folder in my drive already) but for anybody else on the list that the file is newly shared and transferred to, moving it to root does nothing and it remains in All Files without any labels on the file. 它将它发送给我的“我的云端硬盘”,但已复制到我的“我的云端硬盘”中已经存在的文件夹中(因为我已从该驱动器中的文件夹中的文件中复制了该文件),但该列表中的其他人新共享并转移到该文件的操作,将其移至根目录并没有任何作用,并且保留在“所有文件”中,而文件上没有任何标签。

Does anybody have an idea how to move it automatically? 有人知道如何自动移动它吗?

Here is the code that I've been using that works for my own My Drive but nobody else's on the list: 这是我一直在使用的代码,该代码可用于我自己的“我的云端硬盘”,但列表中没有其他代码:

  //Take new file out of parent folders
  var folders = newDoc.getParents();                    //get parents
  for (var j = 0; i < folders.length; i++){             //loop through & delete parents
    DocsList.getFileById(newDocId).removeFromFolder(folders[i]); //using DocsList
  }

  var root = DocsList.getRootFolder(); //Get root

  DocsList.getFileById(newDocId).addToFolder(root); //add to my drive

edit: I was told that transferring ownership should automatically put it into the My Drive file but that isn't happening?? 编辑:有人告诉我,所有权转移应自动将其放入“我的云端硬盘”文件中,但那没有发生?

edit 2: I've tried using "addFile()" which SHOULD add it to My Drive folder in the user's folders, but it only adds it to the my drive of the person running the script and the rest of the users STILL get it only in their "All Items" folder. 编辑2:我尝试使用“ addFile()”,它应该将其添加到用户文件夹的“我的驱动器”文件夹中,但只能将其添加到运行脚本的人的驱动器中,其余用户仍然可以获取它仅在其“所有项目”文件夹中。 This is driving me nuts, someone please help ;C 这让我发疯,有人请帮助; C

So after a few days of driving myself INSANE and asking around literally everywhere I could think of we finally got word that this is an effect of the new Google Drive UI Rollout, so apparently right now it's just like THIS now, until google fixes it :C 因此,经过几天的疯狂驾驶,几乎到处询问,我终于想到了这是新的Google Drive UI推出的效果,因此现在看来,就像现在这样,直到Google修复: C

WHAT AN UNSATISFYING ENDING. 令人不满意的结局。

Unfortunately, it's not going to be possible exactly the way you describe. 不幸的是,这不可能完全按照您的描述进行。

As you've found, the file ownership can be changed. 如您所见,文件所有权可以更改。 That's because you own the file and the file is accessible by Script through the authorization you granted to your Drive account. 这是因为您拥有该文件,并且脚本可以通过您授予云端硬盘帐户的授权来访问该文件。

Placing a file into a location on a different user's Drive is not possible because the script has no privilege to set a location on a Drive it knows nothing about. 无法将文件放置在其他用户的Drive上的某个位置,因为脚本没有特权在不知道的Drive上设置位置。

However, it would be possible to set the location by running a script under each user account, but obviously that's a little arduous to setup and maintain. 但是,可以通过在每个用户帐户下运行脚本来设置位置,但是显然设置和维护起来有些麻烦。

One other option: If you use GAM ( Google Apps Manager ) it IS possible to make changes across accounts. 另一种选择:如果您使用GAM( Google Apps Manager ),则可以跨帐户进行更改。 This is because GAM is run under admin user access. 这是因为GAM是在管理员用户访问权限下运行的。 Example from the GAM site: GAM网站上的示例:

This example updates the "My Ramblings" file to be starred and placed under a folder called "Brilliant things I've said" (assumes a folder by that name already exists for the user) 本示例将“ My Ramblings”文件更新为已加星标,并放置在名为“我所说的精彩内容”的文件夹下(假设用户已经存在该名称的文件夹)

gam user bsmith@acme.com update drivefile drivefilename "My Ramblings" starred true parentname 'Brilliant things I've said'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Google Apps 脚本在 Google Drive 中移动文件夹 - How to move a folder in Google Drive using Google Apps Script 使用 Google Apps 脚本将文件上传到我的 google 驱动器(在 GOOGLE 中没有表格) - Upload file to my google drive with Google Apps Script (NO FORM IN GOOGLE) Google drive - drive.file范围限制了我对共享文件的访问 - Google drive - drive.file scope is restricting my access to a shared file Google Apps 脚本中的“共享驱动器”支持 - “Shared Drive” support in Google Apps Script 共享文件用户无法在 Google Drive API 中使用 drive.file 范围访问文件 - Shared file user can't access files using drive.file scope In google drive API 我如何使用Google App脚本从我的Google驱动器中获取我是所有者的所有文件 - How can i get my all file that i am the owner from my google drive using google app script 使用 Google Apps 脚本将 JSON 文件写入和检索到 Google 云端硬盘 - Write and retrieve JSON file to Google Drive using Google Apps Script 共享文件无法访问(获取共享文件列表)使用 drive.file 范围 Google Drive API - Shared files can't access(get list of shared file) using drive.file scope Google Drive API google.script 使用部分文件名在谷歌驱动器中创建文件夹,然后移动文件 - google.script to make folders in google drive with part of file name and then move files 如何使用Google App脚本将用户选择的文件上传到Google云端硬盘中的文件夹? - How would I go about uploading a user-chosen file to a folder in my Google Drive using Google App Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM