如何使用Google的Python Drive Client API在Team Drive中创建文件夹?

肥猫

我似乎在这方面找不到很多文章。Google的教程仅显示在常规Google云端硬盘文件夹中创建文件夹。

下面是我的功能,它失败了 oogleapiclient.errors.HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files?alt=json returned "File not found: myteamdrivefolderid.". Details: "File not found: myteamdrivefolderid.">

我的应用程序是Python桌面应用程序,并且已经被授权具有完整的云端硬盘读/写范围。

def create_folder(service, name, parent_id=None, **kwargs):
    # Create a folder on Drive, returns the newely created folders ID
    body = {
        'name': name,
        'mimeType': "application/vnd.google-apps.folder"
    }
    if parent_id:
        body['parents'] = [parent_id]
    if 'teamDriveId' in kwargs:
        body['teamDriveId'] = kwargs['teamDriveId']
    folder = service.files().create(body=body).execute()
    return folder['id']
Tanaike

我相信您的目标和情况如下。

  • 您要使用googleapis for python在共享云端硬盘中创建新文件夹。
  • 您有权在共享驱动器中创建新文件夹。
  • 您已经可以使用Drive API。

修改要点:

  • 在这种情况下,请添加supportsAllDrives到查询参数。
  • 似乎teamDriveId已弃用。请使用driveId参考

当以上几点反映到您的脚本时,它将变为以下内容。

修改后的脚本:

body = {
    'name': name,
    'mimeType': "application/vnd.google-apps.folder"
}
if parent_id:
    body['parents'] = [parent_id]
if 'teamDriveId' in kwargs:
    body['driveId'] = kwargs['teamDriveId'] # Modified
folder = service.files().create(body=body, supportsAllDrives=True).execute() # Modified
return folder['id']

参考:

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览

来自分类Dev

使用Google Drive API将文件复制到特定的父文件夹中吗?

来自分类Dev

如何在Google Drive API上按文件夹获取文件列表

来自分类Dev

Google Drive API VB.NET文件夹的父文件夹

来自分类Dev

使用Google Drive Api v3创建文件(javascript)

来自分类Dev

如何查看Google Drive API的文件和文件夹?

来自分类Dev

Google Drive API上传到父文件夹

来自分类Dev

使用Google Drive API创建文件夹:资源没有“插入”方法

来自分类Dev

我如何使用C#从Google Drive API获取文件夹的完整路径

来自分类Dev

结合使用Google Drive API和Java,如何仅列出“驱动器”部分/文件夹中的文件

来自分类Dev

如何为python使用Google Drive API?

来自分类Dev

Google Apps脚本将文件移动到Team Drive文件夹

来自分类Dev

如何在Google Drive API中按路径查找文件夹ID?

来自分类Dev

Google Drive API搜索文件夹

来自分类Dev

Google Drive API Python客户端:批量创建时如何检索已创建文件夹ID的列表?

来自分类Dev

如何使用Google Drive API和Python将文件上传到特定文件夹?

来自分类Dev

如何在Google Drive API中禁用文件夹的递归(Swift 5)

来自分类Dev

在Google Drive API中搜索文件或文件夹时如何获得面包屑?

来自分类Dev

使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览

来自分类Dev

如何在Google Drive Android API中获取已创建文件夹的DriveId

来自分类Dev

Google Drive Web API(Android应用程序)-创建文件在调试中工作正常,在proguard中不工作

来自分类Dev

Google Drive Java Api-文件夹中的更新文件。

来自分类Dev

通过Drive API访问文件夹中的文件?

来自分类Dev

Google Drive API Client (Python):检索权限

来自分类Dev

匿名 Google Drive 上传创建新文件夹

来自分类Dev

使用 Google Drive REST API 创建文件访问请求

来自分类Dev

通过 API 重命名 Google Drive 中的文件夹

来自分类Dev

403:在google drive api php中创建文件夹时权限不足

来自分类Dev

Google Drive API 使用 curl 调用创建文件而不是文件夹

Related 相关文章

  1. 1

    使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览

  2. 2

    使用Google Drive API将文件复制到特定的父文件夹中吗?

  3. 3

    如何在Google Drive API上按文件夹获取文件列表

  4. 4

    Google Drive API VB.NET文件夹的父文件夹

  5. 5

    使用Google Drive Api v3创建文件(javascript)

  6. 6

    如何查看Google Drive API的文件和文件夹?

  7. 7

    Google Drive API上传到父文件夹

  8. 8

    使用Google Drive API创建文件夹:资源没有“插入”方法

  9. 9

    我如何使用C#从Google Drive API获取文件夹的完整路径

  10. 10

    结合使用Google Drive API和Java,如何仅列出“驱动器”部分/文件夹中的文件

  11. 11

    如何为python使用Google Drive API?

  12. 12

    Google Apps脚本将文件移动到Team Drive文件夹

  13. 13

    如何在Google Drive API中按路径查找文件夹ID?

  14. 14

    Google Drive API搜索文件夹

  15. 15

    Google Drive API Python客户端:批量创建时如何检索已创建文件夹ID的列表?

  16. 16

    如何使用Google Drive API和Python将文件上传到特定文件夹?

  17. 17

    如何在Google Drive API中禁用文件夹的递归(Swift 5)

  18. 18

    在Google Drive API中搜索文件或文件夹时如何获得面包屑?

  19. 19

    使用Google Drive API上传PDF文件-Google Drive Web Client中没有预览

  20. 20

    如何在Google Drive Android API中获取已创建文件夹的DriveId

  21. 21

    Google Drive Web API(Android应用程序)-创建文件在调试中工作正常,在proguard中不工作

  22. 22

    Google Drive Java Api-文件夹中的更新文件。

  23. 23

    通过Drive API访问文件夹中的文件?

  24. 24

    Google Drive API Client (Python):检索权限

  25. 25

    匿名 Google Drive 上传创建新文件夹

  26. 26

    使用 Google Drive REST API 创建文件访问请求

  27. 27

    通过 API 重命名 Google Drive 中的文件夹

  28. 28

    403:在google drive api php中创建文件夹时权限不足

  29. 29

    Google Drive API 使用 curl 调用创建文件而不是文件夹

热门标签

归档