如何使用 Microsoft Graph API 获取当前站点的 siteId? [英] How can I get the siteId of the current site with Microsoft Graph API?

查看:108
本文介绍了如何使用 Microsoft Graph API 获取当前站点的 siteId?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档中,我找不到任何方法来获取放置 webpart 的站点的 siteId.

From the documentation, I can't find any ways to get the siteId of the site where I put the webpart in.

例如,

我当前的站点是:https://{hostname}/sites/main1 <-- 不是根站点,但我想获取此站点 ID

My current site is: https://{hostname}/sites/main1 <-- NOT root site, but I want to get this siteId

我在这里测试我的 webpart:https://{hostname}/sites/main1/_layouts/15/workbench.aspx

and I test my webpart here: https://{hostname}/sites/main1/_layouts/15/workbench.aspx

我怎样才能做到这一点?从文档中,

How can I achieve this? From the documentation,

一个站点的地址是一个唯一标识符,它是以下值的复合 ID:

A site is addressed be a unique identifier which is a composite ID of the following values:

网站集主机名 (contoso.sharepoint.com)

Site collection hostname (contoso.sharepoint.com)

网站集唯一 ID (guid)

Site collection unique ID (guid)

站点唯一 ID (guid)

Site unique ID (guid)

我可以通过使用 location.hostname 轻松获取主机名(是的,我使用 JavaScript + React 来构建我的 webpart)但是如何使用 Graph API 轻松获取站点 ID?

I can get the hostname easily by using location.hostname (Yes, I am using JavaScript + React to build my webpart) but how to get the site-id easily with Graph API?

推荐答案

试试这个:https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id例如:https://graph.microsoft.com/v1.0/sites/cie493742.sharepoint.com:/sites/Contoso/Operations/Manufacturing?$select=id(这个你可以试试图浏览器.

Try this: https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id For example: https://graph.microsoft.com/v1.0/sites/cie493742.sharepoint.com:/sites/Contoso/Operations/Manufacturing?$select=id (this one you can try on the Graph Explorer.

您返回的 id 格式如下:

What you get back in the id is in this format:

{hostname},{spsite.id},{spweb.id}. 

有关更多信息,请访问文档链接:https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/site_get

For more info here is the link to the docs: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/site_get

这篇关于如何使用 Microsoft Graph API 获取当前站点的 siteId?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆