如何使用OneDrive for Business API获取文件的修订历史记录

时间:2016-04-08 07:07:45

标签: onedrive

我正在将OneDrive for business(REST API)与我们的平台集成。我可以使用上传API上传文件并更新文件内容。但是如何获取文件的修订历史记录。我正在使用的API如下所示。

Upload a file

2 个答案:

答案 0 :(得分:0)

到目前为止,没有api资源可用于获取文件的版本或修订历史记录。按照link了解一个驱动器中商品的可用操作。

答案 1 :(得分:0)

您无法使用OneDrive for Business API获取文件修订版(版本),但您可以使用SharePoint API来获取它们。

使用此链接获取文件版本:

其中:

" email_tenant_onmicrosoft_com" - 是您的驱动器的电子邮件

" tenant-my.sharepoint.com" - 您的驱动器的终点

此链接的响应看起来像这个JSON:

{
  "odata.metadata": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/$metadata#SP.ApiData.FileVersions",
  "value": [
    {
      "odata.type": "SP.FileVersion",
      "odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/SP.FileVersionf1111111-aaaa-1234-5678-90abcdef1234",
      "odata.editLink": "SP.FileVersionf1111111-aaaa-1234-5678-90abcdef1234",
      "CheckInComment": "",
      "Created": "2013-04-27T15:57:57Z",
      "ID": 512,
      "IsCurrentVersion": false,
      "Length": "5716",
      "Size": 5716,
      "Url": "_vti_history/512/Documents/TEST_005.xlsx",
      "VersionLabel": "1.0"
    },
    {
      "odata.type": "SP.FileVersion",
      "odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/SP.FileVersion2ab46e3e-9614-43ff-ad03-252b1f4d0d90",
      "odata.editLink": "SP.FileVersion2ab46e3e-9614-43ff-ad03-252b1f4d0d90",
      "CheckInComment": "",
      "Created": "2013-04-27T15:58:39Z",
      "ID": 1024,
      "IsCurrentVersion": false,
      "Length": "7868",
      "Size": 7868,
      "Url": "_vti_history/1024/Documents/TEST_005.xlsx",
      "VersionLabel": "2.0"
    },
    {
      "odata.type": "SP.FileVersion",
      "odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/SP.FileVersion42f5f367-05ca-4131-84bf-79e7a6c0f77d",
      "odata.editLink": "SP.FileVersion42f5f367-05ca-4131-84bf-79e7a6c0f77d",
      "CheckInComment": "",
      "Created": "2013-04-27T15:58:43Z",
      "ID": 1536,
      "IsCurrentVersion": false,
      "Length": "7868",
      "Size": 7868,
      "Url": "_vti_history/1536/Documents/TEST_005.xlsx",
      "VersionLabel": "3.0"
    }
  ]
}

重要的参数是:

" odata.editLink"之后" SP.FileVersion" - 它是文件版本的唯一ID。 " ID" - 它是当前文件的版本ID。

要下载文件版本,您可以使用以下链接:

其中" 1024" - 字段" ID"来自JSON。

要获取有关项目最新版本的信息,您可以使用此链接:

此链接的响应看起来像这个JSON:

{
  "odata.metadata": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/$metadata#SP.ApiData.Files12/@Element",
  "odata.type": "SP.File",
  "odata.id": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/_api/Web/GetFileByServerRelativeUrl('/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx')",
  "odata.editLink": "Web/GetFileByServerRelativeUrl('/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx')",
  "CheckInComment": "",
  "CheckOutType": 2,
  "ContentTag": "{C4B73433-8AED-44C2-862A-746EBA4599EB},11,7",
  "CustomizedPageStatus": 0,
  "ETag": "\"{C4B73433-8AED-44C2-862A-746EBA4599EB},11\"",
  "Exists": true,
  "IrmEnabled": false,
  "Length": "7923",
  "Level": 1,
  "LinkingUri": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx?d=wc4b734338aed44c2862a746eba4599eb",
  "LinkingUrl": "https://tenant-my.sharepoint.com/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx?d=wc4b734338aed44c2862a746eba4599eb",
  "MajorVersion": 4,
  "MinorVersion": 0,
  "Name": "TEST_005.xlsx",
  "ServerRelativeUrl": "/personal/email_tenant_onmicrosoft_com/Documents/TEST_005.xlsx",
  "TimeCreated": "2013-04-27T15:57:55Z",
  "TimeLastModified": "2013-04-27T15:59:28Z",
  "Title": null,
  "UIVersion": 2048,
  "UIVersionLabel": "4.0",
  "UniqueId": "c4b73433-8aed-44c2-862a-746eba4599eb"
}

您可以在添加新版本的文件时使用此信息。

"唯一ID" - 它是" odata.editLink"的正确部分。在JSON版本中。 " UIVersion" - 它" ID"在版本JSON。

要下载文件的最新版本 - 请使用以下链接:

链接:

不起作用。如果您添加此文件的新版本,它将起作用。

您可以使用OneDrive API链接下载项目的最新修订版本:

但是如果您使用服务帐户身份验证

,则此链接不起作用
相关问题