繁体   English   中英

Microsoft Graph API:SharePoint:在“根站点”的“默认驱动器”中获取项目列表

[英]Microsoft Graph API: SharePoint: Get items list in "default Drive" of "root Site"

概述

我在使用Microsoft图形API使用文件作用域的根目录中处理项目熟悉,如果在微软OneDrive(具体项目文件夹文件); create/delete/metadataFoldersupload/delete/metadataFiles

再次使用微软图形API,我希望做根网站如上面所提到的默认驱动器中操作文件夹上传/文件删除/元,在微软的SharePoint文件夹和文件,创建/删除/元数据执行相同的操作之前进行驱动器

问题

我在使用 Microsoft Graph API 处理默认驱动器或根站点中的项目时遇到以下问题:

  1. 在处理站点驱动器中的项目时使用默认驱动器 ID。
  2. 在默认站点的驱动器中创建/删除/获取文件夹项的元数据。
  3. 上传/删除/获取父文件夹中文件项的元数据。

以下 Microsoft Graph API 调用返回根站点的默认驱动器元数据**:

curl "https://graph.microsoft.com/v1.0/sites/root/drive" \
--request GET \
--verbose \
--write-out 'HTTPSTATUS:%{http_code}' \
--silent \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"

JSON 响应示例是:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
  "createdDateTime": "2012-06-12T17:27:56Z",
  "description": "Share a document with the team by adding it to this document library.",
  "id": "b!mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60",
  "lastModifiedDateTime": "2015-03-03T02:39:56Z",
  "name": "Shared Documents",
  "webUrl": "https://docusign2com.sharepoint.com/Shared%20Documents",
  "driveType": "documentLibrary",
  "createdBy": {
    "user": {
      "displayName": "System Account"
    }
  },
  "lastModifiedBy": {
    "user": {
      "displayName": "System Account"
    }
  },
  "quota": {
    "deleted": 0,
    "remaining": 0,
    "total": 0,
    "used": 0
  }
}

获取驱动器元数据的问题

获取根站点中当前默认驱动器的未编码drive_id[** DRIVE_ID **]

"id": "b!mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60"

编码drive_id , [** URL-Encoded DRIVE_ID **]

"id": "b%21mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60"

使用编码的 drive_id ,我们可以通过另一种方式获取该驱动器的元数据:

curl "https://graph.microsoft.com/v1.0/sites/root/drives/[** URL-Encoded DRIVE_ID **]" \
--request GET \
--verbose \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"

回复:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
  "createdDateTime": "2012-06-12T17:27:56Z",
  "description": "Share a document with the team by adding it to this document library.",
  "id": "[** DRIVE_ID **]",
  "lastModifiedDateTime": "2015-03-03T02:39:56Z",
  "name": "Shared Documents",
  "webUrl": "https://docusign2com.sharepoint.com/Shared%20Documents",
  "driveType": "documentLibrary",
  "createdBy": {
    "user": {
      "displayName": "System Account"
    }
  },
  "lastModifiedBy": {
    "user": {
      "displayName": "System Account"
    }
  },
  "quota": {
    "deleted": 0,
    "remaining": 0,
    "total": 0,
    "used": 0
  }
}

接下来,我尝试通过附加/items 来列出根站点的默认驱动器中的项目

curl "https://graph.microsoft.com/v1.0/sites/root/drives/[** URL-Encoded DRIVE_ID **]/items" \
--request GET \
--verbose \
--header "authorization: Bearer [** ACCESS_TOKEN **" \
--header "Content-Type: application/json"

它失败了:

{
  "error": {
    "code": "invalidRequest",
    "message": "The request is malformed or incorrect.",
    "innerError": {
      "request-id": "0a212014-b386-45d9-9c36-bae2dd6cea8f",
      "date": "2020-02-07T06:51:15"
    }
  }
}

请求的 API 路径

获取根站点内默认驱动器根目录中所有项目的列表的预期路径是什么?

谢谢

我没有使用.../v1.0/sites/$site_id/drives/...来处理驱动器,而是改用.../v1.0/drives/$drive_id/... ,这有效.

以下 Microsoft Graph API 请求使用/v1.0/sites/root/drives/[** URL-Encoded DRIVE_ID **] ,返回先前获取的默认驱动器(由[** DRIVE_ID **]标识)元数据:

curl "https://graph.microsoft.com/v1.0/drives/[** url-encoded DRIVE_ID **]" \
--request GET \
--verbose \
--silent \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
  "createdDateTime": "2012-06-12T17:27:56Z",
  "description": "Share a document with the team by adding it to this document library.",
  "id": "[** DRIVE_ID **]",
  "lastModifiedDateTime": "2015-03-03T02:39:56Z",
  "name": "Shared Documents",
  "webUrl": "https://docusign2com.sharepoint.com/Shared%20Documents",
  "driveType": "documentLibrary",
  "createdBy": {
    "user": {
      "displayName": "System Account"
    }
  },
  "lastModifiedBy": {
    "user": {
      "displayName": "System Account"
    }
  },
  "quota": {
    "deleted": 0,
    "remaining": 0,
    "total": 0,
    "used": 0
  }
}

这将返回默认驱动器的根文件夹:

curl "https://graph.microsoft.com/v1.0/drives/[** url-encoded DRIVE_ID **]/root" \
--request GET \
--verbose \
--silent \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives('[** url-encoded DRIVE_ID **]')/root/$entity",
  "createdDateTime": "2012-06-12T17:27:56Z",
  "id": "[** ROOT_FOLDER_ID **]",
  "lastModifiedDateTime": "2020-02-07T16:04:09Z",
  "name": "root",
  "webUrl": "https://docusign2com.sharepoint.com/Shared%20Documents",
  "size": 27781340,
  "parentReference": {
    "driveId": "b!mWxqgLJ9mESqZI4PrP0Gs-F4hgLaCRlCkVuON4nbwzhkKbcyWdM1Tb5WEzNJ0C60",
    "driveType": "documentLibrary"
  },
  "fileSystemInfo": {
    "createdDateTime": "2012-06-12T17:27:56Z",
    "lastModifiedDateTime": "2020-02-07T16:04:09Z"
  },
  "folder": {
    "childCount": 5
  },
  "root": {}
}

现在使用默认驱动器的根文件夹,可以请求子文件夹列表:

curl "https://graph.microsoft.com/v1.0/drives/[** url-encoded DRIVE_ID **]/items/[** ROOT_FOLDER_ID **]/children" \
--request GET \
--verbose \
--silent \
--header "authorization: Bearer [** ACCESS_TOKEN **]" \
--header "Content-Type: application/json"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM