目前,我使用 Google Cloud 的 GWT 应用程序遇到问题。
我实际上有一段代码,允许您使用谷歌驱动器应用程序上传文件。
除此之外,随着谷歌的更新,谷歌驱动器上的文件不再可能有多个父级,我们可以在这里看到:
https://cloud.google.com/blog/products/g-suite/simplifying-google-drives-folder-struct-and-sharing-models https://cloud.google.com/blog/products/g-suite/simplifying-google-drives-folder-structure-and-sharing-models
“ 您只能为尚无父项的项目添加父项。这会影响children.insert (v2)、files.update (v2 / v3) 和parents.insert (v2) 端点。您可以使用新的canAddMyDriveParent 能够检查某个项目当前是否没有父项以及用户是否有足够的访问权限来为该项目添加父项。”
所以我有以下代码:
service.files().update(fileId, file).execute();
这会产生一个错误:
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Increasing the number of parents is not allowed",
"reason" : "cannotAddParent"
} ],
"message" : "Increasing the number of parents is not allowed"
}
但我不知道如何上传文件而不出现此错误。
事实上,我不知道如何创建新的父文件夹,或者是否可以在没有父文件夹的情况下上传。
如果有人可以帮助我,任何帮助将不胜感激!
非常感谢!
今年(2020 年)年初,Google 推出了 API,该 API 已发生变化捷径 https://cloud.google.com/blog/products/g-suite/simplifying-google-drives-folder-structure-and-sharing-models:
您只能为尚无父级的项目添加父级。这会影响children.insert (v2)、files.update (v2 / v3) 和parents.insert (v2) 端点。您可以使用新的 canAddMyDriveParent 功能来检查项目当前是否没有父项以及用户是否有足够的访问权限来为该项目添加父项。
该规定于 3 月份宣布,但自 9 月 30 日起实施。
你猜对了:快捷方式 https://developers.google.com/drive/api/v3/shortcuts#create_a_shortcut是在不同文件夹中复制文件的方法,但考虑到它们与原始文件具有不同的特征,并且它们不是“副本”。 MimeType 是application/vnd.google-apps.shortcut
.
创建快捷方式的示例:
file_metadata = {
'name': 'Project Plan',
'mimeType': 'text/plain'
}
file = drive_service.files().create(body=file_metadata, fields='id').execute()
print('File ID: %s' % file.get('id'))
shortcut_metadata = {
'Name': 'Shortcut to Project Plan',
'mimeType': 'application/vnd.google-apps.shortcut',
'shortcutDetails': {
'targetId': file.get('id')
}
}
shortcut = drive_service.files().create(body=shortcut_metadata,
fields='id,shortcutDetails').execute()
print('File ID: %s, Shortcut Target ID: %s, Shortcut Target MIME type: %s' % (
shortcut.get('id'),
shortcut.get('shortcutDetails').get('targetId'),
shortcut.get('shortcutDetails').get('targetMimeType')))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)