【问题标题】:How to get the Site Id of SharePoint using Graph SharePoint Explorer如何使用 Graph SharePoint Explorer 获取 SharePoint 的站点 ID
【发布时间】:2019-11-01 02:11:27
【问题描述】:

如何使用 Microsoft Graph API Explorer 获取 Microsoft SharePoint SiteID。

最初我尝试使用以下 API 我能够获取站点 ID

https://graph.microsoft.com/v1.0/sites/tenantName.sharepoint.com:/sites/TestSite:/drives?select=name,id

共享点网址:

https://tenantName.sharepoint.com/sites/TestSite

我得到的输出是:

{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
"value": [
    {
        "id": "b!l17-JY9YT67Qp-2TBvsUupBLMUF2SrJHp5VylCDZThT7HpCdF-7uQ6NTp6t-MbR5",
        "name": "Documents"
    }
]

}

但是,当我尝试使用通信站点时

谁的 SharePoint URL 是:

https://tenantName.sharepoint.com/SitePages/DevHome.aspx

图形资源管理器 API

https://graph.microsoft.com/v1.0/sites/tenantName.sharepoint.com:/SitePages/DevHome:/drives?select=name,id

我遇到以下错误:

{
"error": {
    "code": "itemNotFound",
    "message": "The provided path does not exist, or does not represent a site",
    "innerError": {
        "request-id": "8329dfca-c63b-4af5-80b8-75f26be9e2e8",
        "date": "2019-10-31T13:18:33"
    }
}

}

【问题讨论】:

    标签: sharepoint microsoft-graph-api


    【解决方案1】:

    sitePagesite 是完全不同的资源。

    • site 是一个容器,它拥有任意数量的子站点、应用程序、列表、文档库等。
    • sitePage 只是site 拥有的另一个资源。
    • sitePage 资源目前仅在 Microsoft Graph Beta 版本中可用。

    所以/SitePages/DevHome.aspx 的查询将是:

    /beta/sites/root/pages/{pageId}
    

    如果您还不知道页面的正确id,您可以根据页面名称过滤SitePage 集合:

    /beta/sites/root/pages?$filter=name eq 'DevHome.aspx'
    

    这将返回一个包含单个实体的集合(DevHome.aspx 页面):

    {
        "@odata.context": "https://graph.microsoft.com/beta/$metadata#sites('root')/pages",
        "value": [
            {
                "eTag": "",
                "id": "{id}",
                "lastModifiedDateTime": "2014-07-10T05:47:29Z",
                "name": "DevHome.aspx",
                "webUrl": "SitePages/DevHome.aspx",
                "createdBy": {
                    "user": {
                        "displayName": "System Account"
                    }
                },
                "lastModifiedBy": {
                    "user": {
                        "displayName": "System Account"
                    }
                },
                "parentReference": {
                    "siteId": "{id}"
                },
                "contentType": {
                    "id": "0x0101080062C83F3CFED6744A882F729480DE6C17",
                    "name": "Wiki Page"
                },
                "webParts": [],
                "publishingState": {
                    "level": "published",
                    "versionId": "1.0"
                }
            }
        ]
    }
    

    我还应该指出,您误解了第一个查询的结果。当您请求/v1.0/sites/{tenant}:/{path}:/drives?select=name,id 时,您不会获得每个Site 的ID,而是获得该Site 中每个Drive 的ID。您可以在站点资源文档的Relationships section 中找到站点中包含的对象

    【讨论】:

    • 您好,先生,我尝试了测试版,但仍然出现错误。下面是我在 Graph API 中尝试的正确 api:我正在尝试使用正确的 api:XXXXXX.sharepoint.com/beta/sites/root/…' 吗?
    • 这不是正确的$filter 子句。应该是?$filter=name eq 'DevHome.aspx'
    【解决方案2】:

    您的 Graph API 调用不正确。 试试这个: https://graph.microsoft.com/v1.0/sites/tenantName.sharepoint.com?select=name,id

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 2017-06-10
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      相关资源
      最近更新 更多