简体   繁体   English

Google Drive 在共享云端硬盘中创建新文件夹

[英]Google Drive create new folder in shared drive

I'm able to create a new folder within a parent folder on my personal Google Drive, but when I try to do it in a shared drive, I get this error:我可以在我的个人 Google Drive 上的父文件夹中创建一个新文件夹,但是当我尝试在共享驱动器中执行此操作时,我收到此错误:

<HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?fields=id&alt=json returned "File not found:

It looks like a similar problem from this question , which wasn't resolved.看起来与this question类似的问题,没有解决。

I'm a manager on the account, and other commands, such as creating new files, work fine.我是该帐户的管理员,其他命令(例如创建新文件)工作正常。

This is the function I'm successfully using when writing to my personal Drive:这是我在写入个人驱动器时成功使用的 function:

def create_folder_in_folder(folder_name,parent_folder_id):

    file_metadata = {
    'name' : folder_name,
    'parents' : [parent_folder_id],
    'mimeType' : 'application/vnd.google-apps.folder'
    }

    file = service.files().create(body=file_metadata,
                                    fields='id').execute()

    print ('Folder ID: %s' % file.get('id')) 

How about this modification?这个改装怎么样?

From:从:

file = service.files().create(body=file_metadata, fields='id').execute()

To:至:

file = service.files().create(body=file_metadata, supportsAllDrives=True, fields='id').execute()
  • supportsAllDrives=True is added. supportsAllDrives=True已添加。
    • I think that the reason of the error message is due to this.我认为错误消息的原因是由于这个。

Note:笔记:

  • In this case, it supposes that you have the permission for creating the folder to the shared Drive.在这种情况下,它假设您具有创建文件夹到共享驱动器的权限。

Reference:参考:

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM