insufficientFilePermissions 错误尝试导出 GDrive 工作区文件时发生

huangapple go评论54阅读模式
英文:

insufficientFilePermissions error when try to export GDrive workspace files

问题

遇到了"insufficientFilePermissions"错误,尝试导出GDrive工作区文件时。

错误信息:

googleapiclient.http: 在请求 https://www.googleapis.com/drive/v3/files/{File_ID}/export?mimeType=application%2Fvnd.oasis.opendocument.presentation&alt=media 时遇到了 403 Forbidden 错误,原因是 "insufficientFilePermissions"。

<HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/{File_ID}/export?mimeType=application%2Fvnd.oasis.opendocument.presentation&alt=media returned "
用户对此文件没有足够的权限。"。 详细信息: "[{
'message': '用户对此文件没有足够的权限。', 
'domain': 'global', 
'reason': 'insufficientFilePermissions'
}]">

我正在使用链接上找到的Python代码。为了测试这段代码,我在我的GDrive帐户上配置了service_account。我能够下载Google工作区文件,并且一切正常运行。但是,相同的代码对于客户GDrive会引发上述错误。我已正确配置了service_account,因为我可以下载除工作区之外的其他GDrive文件。

分享一下,GDrive工作区文件的结构如下:

{
    'kind': 'drive#file',
    'copyRequiresWriterPermission': False,
    'writersCanShare': True,
    'viewedByMe': True,
    'mimeType': 'application/vnd.google-apps.presentation',
    'exportLinks': {
        'application/vnd.oasis.opendocument.presentation': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=odp',
        'application/pdf': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=pdf',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=pptx',
        'text/plain': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=txt'
    },
    'parents': ['root'],
    'thumbnailLink': 'https://docs.google.com/feeds/vt?gd=true&id={file_id}&v=2&s=AMedNnoAAAAAZH2QVm6sssfJMwvO4_wZtTxvWk9-VGZP&sz=s220',
    'iconLink': 'https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.presentation',
    'shared': False,
    'lastModifyingUser': {
        'displayName': '{user_name}',
        'kind': 'drive#user',
        'me': True,
        'permissionId': '{permissionId}',
        'emailAddress': '{email_id}'
    },
    'owners': [{
        'displayName': '{user_name}',
        'kind': 'drive#user',
        'me': True,
        'permissionId': '{permissionId}',
        'emailAddress': '{email_id}'
    }],
    'webViewLink': 'https://docs.google.com/presentation/d/{file_id}/edit?usp=drivesdk',
    'viewersCanCopyContent': True,
    'permissions': [{
        'id': '{permissionId}',
        'displayName': '{user_name}',
        'type': 'user',
        'kind': 'drive#permission',
        'emailAddress': '{email_id}',
        'role': 'owner',
        'deleted': False,
        'pendingOwner': False
    }],
    'hasThumbnail': True,
    'spaces': ['drive'],
    'id': '{file_id}',
    'name': '{file name}',
    'starred': False,
    'trashed': False,
    'explicitlyTrashed': False,
    'createdTime': '2022-02-22T04:05:47.677Z',
    'modifiedTime': '2022-02-22T04:05:51.475Z',
    'modifiedByMeTime': '2022-02-22T04:05:51.475Z',
    'viewedByMeTime': '2022-02-22T04:05:51.475Z',
    'quotaBytesUsed': '0',
    'version': '275',
    'ownedByMe': True,
    'isAppAuthorized': False,
    'capabilities': {
        'canChangeViewersCanCopyContent': True,
        'canEdit': True,
        'canCopy': True,
        'canComment': True,
        'canAddChildren': False,
        'canDelete': True,
        'canDownload': True,
        'canListChildren': False,
        'canRemoveChildren': False,
        'canRename': True,
        'canTrash': True,
        'canReadRevisions': True,
        'canChangeCopyRequiresWriterPermission': True,
        'canMoveItemIntoTeamDrive': True,
        'canUntrash': True,
        'canModifyContent': True,
        'canMoveItemOutOfDrive': True,
        'canAddMyDriveParent': False,
        'canRemoveMyDriveParent': True,
        'canMoveItemWithinDrive': True,
        'canShare': True,
        'canMoveChildrenWithinDrive': False,
        'canModifyContentRestriction': True,
        'canChangeSecurityUpdateEnabled': False,
        'canAcceptOwnership': False,
        'canReadLabels': True,
        'canModifyLabels': True
    },
    'thumbnailVersion': '2',
    'modifiedByMe': True,
    'permissionIds': ['{permissionId}'],
    'linkShareMetadata': {
        'securityUpdateEligible': False,
        'securityUpdateEnabled': True
    }
}

这是您提供的信息的翻译部分。

英文:

Encountered insufficientFilePermissions error when try to export GDrive workspace files.

Error:

googleapiclient.http:Encountered 403 Forbidden with reason "insufficientFilePermissions"
<HttpError 403 when requesting https://www.googleapis.com/drive/v3/files/{File_ID}/export?mimeType=application%2Fvnd.oasis.opendocument.presentation&alt=media returned "
The user does not have sufficient permissions for this file.". Details: "[{
'message': 'The user does not have sufficient permissions for this file.', 
'domain': 'global', 
'reason': 'insufficientFilePermissions'
}]">

I am using python code found at Link

To test the code, I configured service_account on my GDrive account. I am able to download the Google workspace files and it is working fine. But, the same code is throwing above mentioned error for customer GDrive. I configured service_account correctly as able to download rest of the GDrive files other than worksapce.

Sharing, the GDrive workspace file structure is

{
'kind': 'drive#file',
'copyRequiresWriterPermission': False,
'writersCanShare': True,
'viewedByMe': True,
'mimeType': 'application/vnd.google-apps.presentation',
'exportLinks': {
'application/vnd.oasis.opendocument.presentation': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=odp',
'application/pdf': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=pdf',
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=pptx',
'text/plain': 'https://docs.google.com/feeds/download/presentations/Export?id={file_id}&exportFormat=txt'
},
'parents': ['root'],
'thumbnailLink': 'https://docs.google.com/feeds/vt?gd=true&id={file_id}&v=2&s=AMedNnoAAAAAZH2QVm6sssfJMwvO4_wZtTxvWk9-VGZP&sz=s220',
'iconLink': 'https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.presentation',
'shared': False,
'lastModifyingUser': {
'displayName': '{user_name}',
'kind': 'drive#user',
'me': True,
'permissionId': '{permissionId}',
'emailAddress': '{email_id}'
},
'owners': [{
'displayName': '{user_name}',
'kind': 'drive#user',
'me': True,
'permissionId': '{permissionId}',
'emailAddress': '{email_id}'
}],
'webViewLink': 'https://docs.google.com/presentation/d/{file_id}/edit?usp=drivesdk',
'viewersCanCopyContent': True,
'permissions': [{
'id': '{permissionId}',
'displayName': '{user_name}',
'type': 'user',
'kind': 'drive#permission',
'emailAddress': '{email_id}',
'role': 'owner',
'deleted': False,
'pendingOwner': False
}],
'hasThumbnail': True,
'spaces': ['drive'],
'id': '{file_id}',
'name': '{file name}',
'starred': False,
'trashed': False,
'explicitlyTrashed': False,
'createdTime': '2022-02-22T04:05:47.677Z',
'modifiedTime': '2022-02-22T04:05:51.475Z',
'modifiedByMeTime': '2022-02-22T04:05:51.475Z',
'viewedByMeTime': '2022-02-22T04:05:51.475Z',
'quotaBytesUsed': '0',
'version': '275',
'ownedByMe': True,
'isAppAuthorized': False,
'capabilities': {
'canChangeViewersCanCopyContent': True,
'canEdit': True,
'canCopy': True,
'canComment': True,
'canAddChildren': False,
'canDelete': True,
'canDownload': True,
'canListChildren': False,
'canRemoveChildren': False,
'canRename': True,
'canTrash': True,
'canReadRevisions': True,
'canChangeCopyRequiresWriterPermission': True,
'canMoveItemIntoTeamDrive': True,
'canUntrash': True,
'canModifyContent': True,
'canMoveItemOutOfDrive': True,
'canAddMyDriveParent': False,
'canRemoveMyDriveParent': True,
'canMoveItemWithinDrive': True,
'canShare': True,
'canMoveChildrenWithinDrive': False,
'canModifyContentRestriction': True,
'canChangeSecurityUpdateEnabled': False,
'canAcceptOwnership': False,
'canReadLabels': True,
'canModifyLabels': True
},
'thumbnailVersion': '2',
'modifiedByMe': True,
'permissionIds': ['{permissionId}'],
'linkShareMetadata': {
'securityUpdateEligible': False,
'securityUpdateEnabled': True
}

答案1

得分: 2

"用户对此文件没有足够的权限。"

这意味着您正在进行身份验证的用户没有权限访问该文件。您正在使用一个服务帐户,因此有两个选项。

第一,打开服务帐户文件,找到服务帐户的电子邮件地址。它是唯一一个包含@符号的电子邮件地址。然后,像对待其他用户一样,转到Google Drive Web应用程序并与服务帐户共享一个目录。

第二个选项,因为您正在使用Google Workspace,这可能是最佳选项,是由您工作区域域的管理员配置域广泛委派给您的服务帐户。这将授予服务帐户访问权,以模拟工作区域域上的任何用户。然后,您可以在您的代码中指定要模拟的用户。

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    SERVICE_ACCOUNT_FILE_PATH,
    scopes=SCOPES)

credentials = credentials.create_delegated(user_email)

请注意,我将尝试联系团队,询问您发布的链接情况。对我来说,工作区域驱动程序身份验证的文档方式似乎有些奇怪。

英文:

>The user does not have sufficient permissions for this file.

Means exactly that the user that you are authencating with does not have permission to access the file. You are using a service account so you have two options.

One open the service account file find the service account email address. Its the only one with a @ in it go to google drive web app and share a directory with the service account like you would any other user.

The second option because you are using google workspace this is probably the best option would be to have the admin of your workspace domain to configure domain wide delegation for your service account. this will grant the service account access to impersonate any user on the workspace domain. YOu can then specify which user you want to impersonate in your code.

credentials = ServiceAccountCredentials.from_json_keyfile_name(
SERVICE_ACCOUNT_FILE_PATH,
scopes=SCOPES)
credentials = credentials.create_delegated(user_email)

Note im going to see about contacting the team about the link you posted. Seams strange how they have documented workspace drive auth to me.

huangapple
  • 本文由 发表于 2023年6月5日 21:46:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定