SharePoint365 接入简要笔记

一、前言

整体SharePoint 接入主体主要围绕文件的内容问题,最终目的是将SharePoint涉及的文件内容整合打包迁移,所以这里主要关注的内容为文件相关的内容部分,其他有涉及的会列出相关讯息。

二、概念划分

1、网站/新闻

SharePoint这里展示上通常分类为这两个内容。

①新闻服务于网站,也就是依托于网站。

②新闻的素材可以直接从文档库提取。

③文档库可以涵盖你所知道的绝大数内容。

2、公共目录

为组织默认的一个文档目录, 一个商业级的Acount ,都会为其分配一个公共网站目录。

通常我们获取的相对地址的时候,都是基于 Shared Documents目录即可

3、关注目录/文件

主要是已经授予读取权限的网站,我们便可以获取拥有查看权限的文件内容。

①通常为关注整个网站

②可以关注文件/目录

4、签入/签出

其实相当于我们线程阻塞一样,也可以说锁。

签出: 将文档单独拎出,避免其他人操作,你获取了单独修改的权限。

签入: 放回原位,重新释放线程锁。

三、API 操作(sharePoint v1)(针对个人登录用户)

相关接口地址参考:

①通用端点地址: https://docs.microsoft.com/zh-cn/sharepoint/dev/sp-add-ins/get-to-know-the-sharepoint-rest-service?tabs=csom

②社交方面端点地址: https://docs.microsoft.com/zh-cn/sharepoint/dev/general-development/following-people-and-content-rest-api-reference-for-sharepoint#bk_GetFollowersFor

1、前置准备

为了测试数据接口可行性,建议:

①预备一个可行性business Acount。

②公共主页上创建至少一个文件夹,且文件夹内任意放一个文件。

③创建一个新网站,同样创建文件夹及文件。

2、获取登录token

基于这个模式获取的token,需要关闭Azure默认的安全模式。

具体: Azure Active Directory —> 属性 —> 管理安全默认值(设置为否)

2.1、模拟页面登录的模式获取SecurityToken

Endpoint: https://login.microsoftonline.com/extSTS.srf

Method: POST

请求头:

Accept: application/json;odata=verbose

请求体内参数说明:

UserName: 此处填入用户名

Password: 此处填入密码

SharPointAdress: sharepoint 地址,通常为{{domain}}.sharepoint.com

请求体:
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope"
      xmlns:a="http://www.w3.org/2005/08/addressing"
      xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">https://login.microsoftonline.com/extSTS.srf</a:To>
    <o:Security s:mustUnderstand="1"
       xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <o:UsernameToken>
        <o:Username>{{UserName}}</o:Username>
        <o:Password>ringofor6?</o:Password>
      </o:UsernameToken>
    </o:Security>
  </s:Header>
  <s:Body>
    <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
      <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
        <a:EndpointReference>
          <a:Address>{{SharPointAdress}}</a:Address>
        </a:EndpointReference>
      </wsp:AppliesTo>
      <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
      <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
      <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
    </t:RequestSecurityToken>
  </s:Body>
</s:Envelope>
正常响应:

定位BinarySecurityToken标签即可

 <wsse:BinarySecurityToken Id="Compact0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">t=EwDwAk6hBwAUSmCQQlqR5MKj0PCkIZAplWMov+YAARQxiXpNh71Wjd3/I8j7dYLc6v+mmYPhv+MXYG6EHgHk+sgAo23kodTVN5siS9jH7Kc4df29Q4sliRmlCWkXNdEVgrZDgwg60g8Sfu7fwlFBQNEOYhVZltmCUr5VZgU4onTpHAbg9bkiW78tiXUrGD45kpJN7xk+9TpTv10ilolPxhnGh7twe756cBMwUkmSH1d/JL2ddfzXT4nVkVG4IHUavXCIF43CPBYwIJOZZwBseDIqsA9JWxJvwSK+c+Cxoww/y32uZ8flLMKy4WeumgboADqYGxGig/EY0RJDus7DD14ZqB+h9F1H26GSEjc21gH5WtqG4h2990XUSEi2Gw0DZgAACBypP6+DimiUwAH1We5a17tELMluinkxCUxgJZQ043oSTCrqE/lnmjmfkCO1A8LJcdEkQkXb5kP0ecuS9AaOOKQT7hL1Ne1m01WNPJbjOXbXjSX648wiP7sx1s8AfSihrVyJyuyLwTFr1QJZtKZ3fMgL4wYanP6jYaPCzMilL0ef5vq2AatBkaeQbgx65D9S4yXprQneLmZbrlFXt4WYNxsMBka8PU0RrRBeVepKTf+lmVz6+VrInAmWsiCkSyJ5NF9QwtKmgF0KLtWpCO4bzNMakANUHiwS6cQ3aZQ8ZFFUcbJf/TIRWTtWOHUA06PmU5WDvszwS9PBrwb02lqnAP3a2zzq8RRlnsQdpdujfOEv/3wWAx/1iH/FrEWkDy0okEv3tDZjz+ZlMtBMb48Y07WyeWyO+wAKV+PGlhEP9fT4rev/tIa82RX3xf1dRkKsOylK8uhX929tiqNxY7t72JoZG5euarEXljDuLAsGVc7lz2obkJalHIKn9LYqGsxXpkZerk7+R3oQySE4kotyT2iat9+QTvm62+ghRdjF7F90N72NTuPvZAcrICRsOzgRCY0WomZ+SxktXNhSl6mwUEPSQWQ1zRFTUbtELgI=&amp;p=</wsse:BinarySecurityToken>
非正常响应:

通常为出现 53003:Access has been blocked by Conditional Access policies

需要关闭默认安全设置,参考第三点第2小点

2.2、获取登录后的cookies

利用securityToken请求这个端点,主要是需要获取请求响应中的cookies,为下一步获取真正的token作准备

Endpoint: https://{{domain}}.sharepoint.com/_forms/default.aspx?wa=wsignin1.0

Method: POST

请求体参数说明:

直接将第一步获取的BinarySecurityToken填入请求体即可

请求体:
{{BinarySecurityToken}}
响应头:

我们需要从响应头中获取FedAuth

2.3、获取真正的access token

利用上一步获取的cookies值作为请求附带即可

Endpoint: https://{{domain}}}.sharepoint.com/_api/contextinfo

Method: POST

正常响应:

定位标签:FormDigestValue就是我们需要定位的token

<?xml version="1.0" encoding="utf-8"?>
<d:GetContextWebInformation xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" m:type="SP.ContextWebInformation">
    <d:FormDigestTimeoutSeconds m:type="Edm.Int32">1800</d:FormDigestTimeoutSeconds>
    <d:FormDigestValue>xx9D3C71AF83CA01671A6ECE8A7547BB4A56E33412BCC7541ADB0E8B01B02BE022948F6A341BA8AA0F190DE35EB485124EAB58265D084BF75E8D78B42F5FF8504,13 Jul 2022 02:22:21 -0000</d:FormDigestValue>
    <d:LibraryVersion>16.0.22629.12003</d:LibraryVersion>
    <d:SiteFullUrl>https://{{domain}}.sharepoint.com</d:SiteFullUrl>
    <d:SupportedSchemaVersions m:type="Collection(Edm.String)">
        <d:element>14.0.0.0</d:element>
        <d:element>15.0.0.0</d:element>
    </d:SupportedSchemaVersions>
    <d:WebFullUrl>https://{{domain}}.sharepoint.com</d:WebFullUrl>
</d:GetContextWebInformation>

3、通用Api操作

前置条件: 获取了access token

类型说明:

我们可以根据接口参数中返回的__metadata-> type 来判断

SP.Folder: 文件夹类型

SP.File: 文件类型

Collection(SP.Social.SocialActor): 社交类内容数据

3.1、获取当前公共目录结构

Endpoint: https://{{domain}}.sharepoint.com/_api/web/GetFolderByServerRelativePath(decodedUrl=‘Shared Documents’)

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose

响应示例:

基于示例边幅过大,简略说明,并不会全部展示

{
    "d": {
          "__metadata": {
            ...
            "type": "SP.Folder"
        },
		...
        "Exists": true,
        "IsWOPIEnabled": false,
        "ItemCount": 5,
        "Name": "Shared Documents",
        "ProgID": null,
        "ServerRelativeUrl": "/Shared Documents",
        "TimeCreated": "2022-06-25T15:20:17Z",
        "TimeLastModified": "2022-07-11T07:25:38Z",
        "UniqueId": "e0cebed2-b84a-485d-903e-ab6acb4f77ca",
        "WelcomePage": ""
    }
}

3.2、获取当前公共目录下的所有文件

Endpoint: https://{{domain}}.sharepoint.com/_api/web/GetFolderByServerRelativePath(decodedUrl=‘Shared Documents’)/Files

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose

响应内容:

为方便测试结果:已经在公共目录下创建了一个文件:test.jpg

{
    "d": {
        "results": [
            {  "__metadata": 
             {
                 ...
                 "type": "SP.File"
             },
              "CheckInComment": "",
                "CheckOutType": 2,
                "ContentTag": "{6B757991-6665-4D33-A96D-A64852C0C6BF},1,2",
                "CustomizedPageStatus": 0,
                "ETag": "\"{6B757991-6665-4D33-A96D-A64852C0C6BF},1\"",
                "Exists": true,
                "IrmEnabled": false,
                "Length": "13582",
                "Level": 1,
                "LinkingUri": null,
                "LinkingUrl": "",
                "MajorVersion": 1,
                "MinorVersion": 0,
                "Name": "test.jpg",
                "ServerRelativeUrl": "/Shared Documents/test.jpg",
                "TimeCreated": "2022-07-08T07:25:26Z",
                "TimeLastModified": "2022-07-08T07:25:26Z",
                "Title": null,
                "UIVersion": 512,
                "UIVersionLabel": "1.0",
                "UniqueId": "6b757991-6665-4d33-a96d-a64852c0c6bf"
            }
        ]
    }
}

3.3、获取指定文件讯息

Endpoint: http://{{domain}}.sharepoint.com/_api/web/GetFileByServerRelativePath(decodedUrl=‘/Shared Documents/test.jpg’)

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose

响应内容:

{
    "d": {
             "__metadata": 
             {
                 ...
                 "type": "SP.File"
             },
              "CheckInComment": "",
                "CheckOutType": 2,
                "ContentTag": "{6B757991-6665-4D33-A96D-A64852C0C6BF},1,2",
                "CustomizedPageStatus": 0,
                "ETag": "\"{6B757991-6665-4D33-A96D-A64852C0C6BF},1\"",
                "Exists": true,
                "IrmEnabled": false,
                "Length": "13582",
                "Level": 1,
                "LinkingUri": null,
                "LinkingUrl": "",
                "MajorVersion": 1,
                "MinorVersion": 0,
                "Name": "test.jpg",
                "ServerRelativeUrl": "/Shared Documents/test.jpg",
                "TimeCreated": "2022-07-08T07:25:26Z",
                "TimeLastModified": "2022-07-08T07:25:26Z",
                "Title": null,
                "UIVersion": 512,
                "UIVersionLabel": "1.0",
                "UniqueId": "6b757991-6665-4d33-a96d-a64852c0c6bf"
            }
    }
}

3.4、下载指定文件

Endpoint: http://{{domain}}.sharepoint.com/_api/web/GetFileByServerRelativePath(decodedUrl=‘/Shared Documents/test.jpg’)/$value

请求头:

Authorization:{{access token}}

其实就是指令符:$value

3.5、获取关注内容

Endpoint: https://{{domain}}.sharepoint.com/_api/social.following/my/followed(types=15)

type值是组合值:用户 = 1,文档 = 2,站点 = 4,标签 = 8。允许按位组合

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose

响应内容:

为方便测试结果:已经创建了一个网站:demo,并于网站下创建了目录demo 及文件test.jpg

{
    "d": {
        "Followed": {
            "__metadata": {
                "type": "Collection(SP.Social.SocialActor)"
            },
            "results": [
                {
                    "ActorType": 2,
                    "CanFollow": true,
                    "ContentUri": "https://{{domain}}.sharepoint.com/sites/demo",
                    "GroupId": "00000000-0000-0000-0000-000000000000",
                    "Id": "8.ac0932d648894a7aac1369374c81b689.1d3eddd53113474aa8a84db493774f6d.ac0932d648894a7aac1369374c81b689.00000000000000000000000000000000",
                    "IsFollowed": true,
                    "Name": "demo",
                    "Status": 0,
                    "TagGuid": "00000000-0000-0000-0000-000000000000",
                    "Title": "demo",
                    "Uri": "https://{{domain}}.sharepoint.com/sites/demo"
                },
                {
                    "ActorType": 1,
                    "CanFollow": false,
                    "ContentUri": "https://{{domain}}.sharepoint.com/Shared Documents/demo/test.txt",
                    "GroupId": "00000000-0000-0000-0000-000000000000",
                    "Id": "2.ceac4859fce64a628f11637bf654ded7.7b41bbd446cb4244a80eedb78e934726.277493411bb64172b1d0b7741c413aa9.107cab05d2084824a8503c9a451848cd",
                    "IsFollowed": true,
                    "Name": "test.txt",
                    "Status": 0,
                    "TagGuid": "00000000-0000-0000-0000-000000000000",
                    "Uri": "https://{{domain}}.sharepoint.com/Shared Documents/demo/test.txt"
                }
            ]
        }
    }
}

3.6、获取关注内容数量

Endpoint: https://{{domain}}.sharepoint.com/_api/social.following/my/followedcount(types=15)

type值是组合值:用户 = 1,文档 = 2,站点 = 4,标签 = 8。允许按位组合

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose

{
    "d": {
        "FollowedCount": 2
    }
}

3.7、获取关注内容公共目录结构

与获取本身公共目录差异仅仅是增添关注目录的相对地址(为了便于展示示例,这里存在一个网站demo,已关注。)

EndPoint: https://{{domain}}.sharepoint.com/sites/demo/_api/web/GetFolderByServerRelativePath(decodedUrl=‘Shared Documents’)

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose

响应内容

响应内容与3.1结构一致

3.8、其他关注内容操作(通用)

其实与公共目录相差异的部分就是:增添关注目录的相对地址

①获取关注内容的目录所有文件

Endpoint:{{SharePointAdress}}/sites/demo/_api/web/GetFolderByServerRelativePath(decodedUrl=‘Shared Documents’)/Files

②获取关注内容文件

Endpoint:{{SharePointAdress}}/sites/demo/_api/web/GetFolderByServerRelativePath(decodedUrl=‘Shared Documents/test.jpg’)

③下载关注内容文件

Endpoint:{{SharePointAdress}}/sites/demo/_api/web/GetFolderByServerRelativePath(decodedUrl=‘Shared Documents/test.jpg’)/$value

Method: GET

请求头:

Authorization:{{access token}}

Accept: application/json;odata=verbose (下载部分不需要这个请求头)

四、API操作(graph)(针对business acount)

1、创建应用

为执行graph 的api调用,需要创建一个应用先。参考步骤

2、通过graph浏览器选择适合的api

基于graph我们可以直接进入微软的api浏览器来选择合适的api

参考鏈接: https://developer.microsoft.com/zh-cn/graph/graph-explorer

api参考鏈接: https://docs.microsoft.com/zh-cn/graph/api/overview?view=graph-rest-1.0

3、基于应用客户端密码获取的token

Endpoint: https://login.microsoftonline.com/{{tenant}}/oauth2/v2.0/token

{{tenant}}对应租户id

Method: Post

Content-Type: application/x-www-form-urlencoded

示例使用sharePoint客户端密码

机密id: ce6caa92-15b4-46bb-b77e-233ad64d3d03

值: Wac8QHRMiq-.UVWO_fkF6_LV144YPMyf_Iuc-O

参数名描述说明
client_id客户端id
scope范围,默认其实https://graph.microsoft.com/.default
client_secret客户端密码
grant_type固定值client_credentials

示例响应

{
    "token_type": "Bearer",
    "expires_in": 3599,
    "ext_expires_in": 3599,
    "access_token": "eyJ0eXAiOiJKV1QiLCJub25jZSI6I..."
}

4、涉及的角色权限

1.1 用户部分

User.Read.All、User.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All

1.2 网站部分

Sites.Read.All、Sites.ReadWrite.All

5、通用Api部分

Api筛选技巧:

可以利用 $select 参数来筛选返回的讯息,参数以,分割。

提供示例:5.1

5.1、查看租户讯息

Endpoint: https://graph.microsoft.com/v1.0/users

Method: GET

请求头:

Authorization: {{access token}}

正常响应数据:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users",
    "value": [
        {
            "businessPhones": [
                "15902051304"
            ],
            "displayName": "LinRingo",
            "givenName": "Ringo",
            "id": "1cc865b9-bf0d-46c0-89c5-850c01efffff",
            "mail": "LinRingo@Sample.onmicrosoft.com",
            "preferredLanguage": "zh-CN",
            "surname": "Lin",
            "userPrincipalName": "LinRingo@Sample.onmicrosoft.com"
        }
    ]
}

筛选示例

Endopoint: https://graph.microsoft.com/v1.0/users?$select=displayName,mail

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(displayName,mail)",
    "value": [
        {
            "displayName": "LinRingo",
            "mail": "LinRingo@Sample.onmicrosoft.com",
        }
    ]
}

5.2 、指定租户讯息

需要存在一个租户,用以调用接口

举例租户: LinRingo@Sample.onmicrosoft.com

Endpoint: https://graph.microsoft.com/v1.0/users/{{user-id | user-mail}}

Method: GET

请求头:

Authorization: {{access token}}

参数值说明:

#参照5.1 返回讯息
{{user-id}}: 对应 id ,也就是 1cc865b9-bf0d-46c0-89c5-850c01efffff
# Endpoint:  https://graph.microsoft.com/v1.0/users/1cc865b9-bf0d-46c0-89c5-850c01efffff
{{user-mail}}: 对应mail,也就是 LinRingo@Sample.onmicrosoft.com
# Endpoint:	 https://graph.microsoft.com/v1.0/users/LinRingo@Sample.onmicrosoft.com

5.3、获取公共根目录

通常指的是获取当前商业用户的公共目录

Endpoint: https://graph.microsoft.com/v1.0/sites/root

Method: GET

请求头:

Authorization: {{access token}}

正常响应:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
    "createdDateTime": "2022-07-08T06:46:13.347Z",
    "description": "",
    "id": "sample.sharepoint.com,ceac4859-fce6-4a62-8f11-637bf654de37,7b41bbd4-46cb-4244-a80e-edb78e9356",
    "lastModifiedDateTime": "2022-07-18T02:17:09Z",
    "name": "",
    "webUrl": "https://sample.sharepoint.com",
    "displayName": "Communication site",
    "root": {},
    "siteCollection": {
        "hostname": "sample.sharepoint.com"
    }
}

5.4、获取公共根目录的驱动器

通常指的是公共根目录下的网站列表

Endpoint: https://graph.microsoft.com/v1.0/sites/{{hostname | site-id }}/drives

Method: GET

请求头:

Authorization: {{access token}}

参数值说明:

#参照5.3 返回讯息
{{hostname }}: 对应 hostname ,也就是 sample.sharepoint.com
# Endpoint:  https://graph.microsoft.com/v1.0/sites/sample.sharepoint.com/drives
{{site-id}}: 对应id,也就是 sample.sharepoint.com,ceac4859-fce6-4a62-8f11-637bf654de37,7b41bbd4-46cb-4244-a80e-edb78e9356
# Endpoint:	 https://graph.microsoft.com/v1.0/sites/sample.sharepoint.com,ceac4859-fce6-4a62-8f11-637bf654de37,7b41bbd4-46cb-4244-a80e-edb78e9356/drives

正常响应:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value": [
        {
            "createdDateTime": "2022-06-25T15:20:17Z",
            "description": "",
            "id": "b!WUiszub8YkqPEWN79lTe19S7QXvLRkRCqA7tt46TRyZJkULnXAN7Q6hrVWfffK",
            "lastModifiedDateTime": "2022-07-11T07:25:38Z",
            "name": "Documents",
            "webUrl": "https://sample.sharepoint.com/Shared%20Documents",
            "driveType": "documentLibrary",
		...
        }
    ]
}

5.5、获取根目录下的驱动器文件夹列表

Endpoint: https://graph.microsoft.com/v1.0/sites/{{hostname | site-id }}/drives/{{drive-id}}/root/children

Method: GET

请求头:

Authorization: {{access token}}

参数值说明:

#参照5.3 返回讯息
{{hostname }}: 对应 hostname ,也就是 sample.sharepoint.com

{{site-id}}: 对应id,也就是 sample.sharepoint.com,ceac4859-fce6-4a62-8f11-637bf654de37,7b41bbd4-46cb-4244-a80e-edb78e9356

#参考5.4 返回讯息
{{drive-id}}:对应id,也就是 b!WUiszub8YkqPEWN79lTe19S7QXvLRkRCqA7tt46TRyZJkULnXAN7Q6hrVWfffK

正常响应:

为了返回数据,创建了文件夹 ha、demo。

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('sample.sharepoint.com')/drives('b%21WUiszub8YkqPEWN79lTe19S7QXvLRkRCqA7tt46TRyZJkULnXAN7Q6hrVWAm8ss')/root/children",
    "value": [
        {
            "createdDateTime": "2022-07-11T07:25:38Z",
            "eTag": "\"{63E6A53A-0179-4795-984D-09BC54387E35},1\"",
            "id": "01DXFOSYR2UXTGG6IBSVDZQTIJXRKDQ7RV",
            "lastModifiedDateTime": "2022-07-11T07:25:38Z",
            "name": "demo",
            "webUrl": "https://sample.sharepoint.com/Shared%20Documents/demo",
            "cTag": "\"c:{63E6A53A-0179-4795-984D-09BC54387E35},0\"",
            "size": 0,
			...
        },
        {
            "createdDateTime": "2022-07-08T10:13:23Z",
            "eTag": "\"{ACF076D2-3311-49FA-A9AC-A295AF71FAA6},1\"",
            "id": "01DXFOSYWSO3YKYEJT7JE2TLFCSWXXD6VG",
            "lastModifiedDateTime": "2022-07-08T10:13:23Z",
            "name": "ha",
            "webUrl": "https://sample.sharepoint.com/Shared%20Documents/ha",
            "cTag": "\"c:{ACF076D2-3311-49FA-A9AC-A295AF71FAA6},0\"",
            "size": 13582,
			...
        },
    ]
}

5.6、获取指定根目录下的驱动器文件夹内的文件列表

Endpoint: https://graph.microsoft.com/v1.0/sites/{{hostname | site-id }}/drives/{{drive-id}}/root/children/{{ folder}}/children

Method: GET

请求头:

Authorization: {{access token}}

参数值说明:

#参照5.3 返回讯息
{{hostname }}: 对应 hostname ,也就是 sample.sharepoint.com

{{site-id}}: 对应id,也就是 sample.sharepoint.com,ceac4859-fce6-4a62-8f11-637bf654de37,7b41bbd4-46cb-4244-a80e-edb78e9356

#参考5.4 返回讯息
{{drive-id}}:对应id,也就是 b!WUiszub8YkqPEWN79lTe19S7QXvLRkRCqA7tt46TRyZJkULnXAN7Q6hrVWfffK

#参考5.5 返回讯息
{{folder}}: 对应返回值的 name,比如 demo 或 ha

正常响应:

Endpoint: https://graph.microsoft.com/v1.0/sites/{{hostname | site-id }}/drives/{{drive-id}}/root/children/{{ folder}}/children

这里{{folder}}采用了demo,同时为了展示效果,为demo文件夹下创建了text.txt文件

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('sample.sharepoint.com')/drives('b%21WUiszub8YkqPEWN79lTe19S7QXvLRkRCqA7tt46TRyZJkULnXAN7Q6hrVWAmfff')/root/children('demo')/children",
    "value": [
        {
            "@microsoft.graph.downloadUrl": "https://sampleforrobot.sharepoint.com/_layouts/15/download.aspx?..",
            "createdDateTime": "2022-07-11T07:41:41Z",
            "eTag": "\"{27749341-1BB6-4172-B1D0-B7741C413AA9},2\"",
            "id": "01DXFOSYSBSN2CPNQ3OJA3DUFXOQOECOVJ",
            "lastModifiedDateTime": "2022-07-11T07:42:22Z",
            "name": "test.txt",
            "webUrl": "https://sample.sharepoint.com/Shared%20Documents/demo/test.txt",
            "cTag": "\"c:{27749341-1BB6-4172-B1D0-B7741C413AA9},2\"",
            "size": 0,
        }
    ]
}

5.7、获取用户关注的网站讯息

通常我们需要根据用户讯息才能获取用户关注的内容,剩下的文件方面的操作与通用部分一致。

Endpoint: https://graph.microsoft.com/v1.0/users/{{user-id}}/followedSites

Method: GET

请求头:

Authorization: {{access token}}

参数值说明:

#参考 5.1 返回讯息
{{user-id}}:对应用户id 1cc865b9-bf0d-46c0-89c5-850c01efffff

正常响应:

为了正常响应讯息,创建了网站fwaf,并且关注

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
    "value": [
        {
            "description": "",
            "id": "sample.sharepoint.com,2deb3c6f-aedf-4466-bc3b-47ef5494a9f4,a41ed731-aee3-48ff-a810-7f63f72c99f3",
            "lastModifiedDateTime": "2022-07-08T07:39:20Z",
            "webUrl": "https://sample.sharepoint.com/sites/fwaf",
            "displayName": "fwaf",
            "sharepointIds": {
                "listItemId": "1",
                "siteId": "2deb3c6f-aedf-4466-bc3b-47ef5494a9f4",
                "siteUrl": "https://sample.sharepoint.com/sites/fwaf",
                "webId": "a41ed731-aee3-48ff-a810-7f63f72c99f3"
            },
            "siteCollection": {
                "hostname": "sample.sharepoint.com"
            }
        }
    ]
}

5.8、关注网站的根目录驱动器

Endpoint: https://graph.microsoft.com/v1.0/sites/{{host-name}}:/sites/{{site-name}}:/drives

Method: GET

请求头:

Authorization: {{access token}}

参数值说明:

#参考5.7 返回讯息
{{host-name}}: 对应siteCollection - hostname ,即 sample.sharepoint.com

{{site-name}}: 对应displayName ,即 fwaf

正常响应:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value": [
        {
            "createdDateTime": "2022-06-25T15:25:14Z",
            "description": "",
            "id": "b!bzzrLd-uZkS8O0fvVJSp9DHXHqTjrv9IqBB_Y_csmfOV2z-BBfvxTow89Tm_d47a",
            "lastModifiedDateTime": "2022-07-08T09:21:30Z",
            "name": "文档",
            "webUrl": "https://sample.sharepoint.com/sites/fwaf/Shared%20Documents",
            "driveType": "documentLibrary",
        }
    ]
}

5.7、关注网站的其他操作

其实这里已经与上面获取自己公共操作方式一样

①获取关注根目录驱动器下的文件列表

Endpoint: https://graph.microsoft.com/v1.0/sites/{{host-name}}/drives/{{drive-id}}/root/children

②获取关注根目录驱动器下的文件夹内的文件列表:

Endpoint: https://graph.microsoft.com/v1.0/sites/{{hostname | site-id }}/drives/{{drive-id}}/root/children/{{ folder}}/children

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值