【问题标题】:how to get the resourcekey from google drive api如何从 google drive api 获取资源密钥
【发布时间】:2021-08-17 04:57:39
【问题描述】:

我正在尝试从 google drive api 获取文件的资源密钥

在google api的描述中 9 月 13 日,他们将更新文件许可 他们说 '您必须更新访问文件的代码以包含适当的资源键' '在 Drive API 响应中文件元数据的 resourceKey 字段中返回项目的资源密钥'

但是当我尝试获取文件时,我无法从文件元数据的字段中找到资源键 而且当我尝试在google api测试中进行时,响应也没有资源键 下面是api测试的结果

{
 "kind": "drive#file",
 "id": "1iLXfgFeTJi5Fhv",
 "etag": "\"MTYyODc0MTU1ODg4Nw\"",
 "selfLink": "https://www.googleapis.com/drive/v2/files/1iLXfgFeTJi5Fhv",
 "alternateLink": "https://docs.google.com/spreadsheets/d/1iLXfgFeTJi5Fhv/edit?usp=drivesdk",
 "embedLink": "https://docs.google.com/spreadsheets/d/1iLXfgFeTJi5Fhv",
 "iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.spreadsheet",
 "thumbnailLink": "https://docs.google.com/feeds/vt?gd=true&id=1iLXfgFeTJi5Fhv&v=3&s=AMedNnoAAAAAYRtUMTI6h451YaMRq96KNGUB_WwYBPDv&sz=s220",
 "title": "CSS_v1_212232173224",
 "mimeType": "application/vnd.google-apps.spreadsheet",
 "labels": {
  "starred": false,
  "hidden": false,
  "trashed": false,
  "restricted": false,
  "viewed": true
 },
 "copyRequiresWriterPermission": false,
 "createdDate": "2021-08-12T04:10:07.115Z",
 "modifiedDate": "2021-08-12T04:12:38.887Z",
 "lastViewedByMeDate": "2021-08-17T04:16:16.628Z",
 "markedViewedByMeDate": "1970-01-01T00:00:00.000Z",
 "sharedWithMeDate": "2021-08-17T04:16:16.628Z",
 "version": "10",
 "parents": [],
 "exportLinks": {
  "application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv",
  "text/tab-separated-values": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv&exportFormat=tsv",
  "application/pdf": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv&exportFormat=pdf",
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv4&exportFormat=xlsx",
  "text/csv": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv&exportFormat=csv",
  "application/zip": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv&exportFormat=zip",
  "application/vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=1iLXfgFeTJi5Fhv&exportFormat=ods"
 },
 "userPermission": {
  "kind": "drive#permission",
  "etag": "\"kKO0QvvB0TR5MI4KTDoDeWQE7AU\"",
  "id": "me",
  "selfLink": "https://www.googleapis.com/drive/v2/files/1iLXfgFeTJi5Fhv/permissions/me",
  "role": "reader",
  "type": "user"
 },
 "fileSize": "13706",
 "quotaBytesUsed": "13706",
 "ownerNames": [
  ""
 ],
 "owners": [
  {
   "kind": "drive#user",
   "displayName": "",
   "isAuthenticatedUser": false,
   "permissionId": "",
   "emailAddress": ""
  }
 ],
 "lastModifyingUserName": "",
 "lastModifyingUser": {
  "kind": "drive#user",
  "displayName": "",
  "isAuthenticatedUser": false,
  "permissionId": "",
  "emailAddress": ""
 },
 "capabilities": {
  "canCopy": true,
  "canEdit": false
 },
 "editable": false,
 "copyable": true,
 "writersCanShare": true,
 "shared": true,
 "explicitlyTrashed": false,
 "appDataContents": false,
 "spaces": [
  "drive"
 ]
}

我怎样才能得到文件的resourcekey??

【问题讨论】:

  • 我无法让它工作,或者我已经在 google 上 ping 了某人,当我听到什么时会回复你。

标签: google-drive-api


【解决方案1】:

您需要转到 Google 管理员,确保您的域中的 resourceKey 安全更新已激活。你可以在这里找到更详细的答案https://issuetracker.google.com/issues/196862507

【讨论】:

  • 您好,我在 Google Admin 上检查了安全更新。但这已经像您的答案一样更新了。然后我再次尝试您的 api 站点上的 api,但我仍然无法获取资源密钥(developers.google.com/drive/api/v3/reference/files/get)resourceKey 更新是否正确?文件的get方法给出resourceKey是否正确?
  • 问题跟踪器的链接已失效您有更新的链接吗?
  • 哦,我看不到 issuetracker.. 你能再给我点赞吗??
【解决方案2】:

新更新

第 3 阶段:云端硬盘强制更新 - 从 2021 年 9 月 13 日开始 更新应在 2021 年 9 月底前完成。

应用安全更新:

  1. 登录您的 Google 管理控制台。
  2. 从管理控制台首页,转到应用程序,然后转到 Google Workspace,然后转到云端硬盘和文档。
  3. 单击共享设置,然后单击文件的安全更新。
  4. 选择如何应用更新:
  5. 将安全更新应用到所有受影响的文件
  6. 从所有受影响的文件中删除安全更新(不推荐) (如果应用更新,则可选)要让用户删除或应用更新到他们拥有或管理的文件,请选中允许框。 如果您进行了任何更改,请点击保存。

等待更改影响(可能长达 24 小时)

如何验证设置

打开谷歌驱动器(搜索框)

  • is:security_update_applied
  • is:security_update_applied type:folder

结果:

获取文件的API

https://www.googleapis.com/drive/v3/files/${file_id}?fields=*

https://developers.google.com/drive/api/v3/reference/files

- shortcutDetails.targetResourceKey string  The ResourceKey for the target file.    
- resourceKey   string  A key needed to access the item via a shared link.

所以以前看起来像https://drive.google.com/file/d/${file_id}/的链接

现在看起来像 https://drive.google.com/file/d/${file_id}/view?resourcekey=xxxx-xxxx-xxxx-xxx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多