簡體   English   中英

如何使用 Graph API 為 onenote 部分創建共享點鏈接

[英]How to create a sharepoint link for a onenote section, using Graph API

我在 .Net 中使用 Graph API 來訪問客戶端 Sharepoint 中的 OneNote 筆記本。 到目前為止,一切都很好。 我可以訪問筆記本,並循環瀏覽各個部分。

但是,要求我以https://companyname.sharepoint.com/sites/NotebookName/_layouts/15/Doc.aspx?sourcedoc={7636j9a7-2364-4b40的形式返回筆記本部分的共享點鏈接-8h33-c6ba539f98cd}&action=edit&wd=target%28SectionName.one%7C5jd216c9-bcn4-43e2-896e-86p2b765a415%2F%29&wdorigin=717

使用 Graph API,我得到了這樣一個 URL: https ://graph.microsoft.com/v1.0/sites/companyname.sharepoint.com,81ba2d09-8378-5d84-b365-9gd9bb83f9c3,f5bd4b76-7796-4354- 8d53-07d5dbb843f6/onenote/sections/1-328ab290-37bd-4495-9009-2437bef11d54/pages

我無法從 graph-api url 獲取共享點 url。 是否可以使用 Graph API 構建像上面那樣的共享點 url?

這是我正在使用的代碼:

`

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);

            var site = await graphClient.Sites.GetByPath("/sites/NoteBookName", "companyname.sharepoint.com")
                .Request()
                .GetAsync();

            var notebooks = await graphClient.Sites[site.Id]
                .Onenote
                .Notebooks
                .Request()
                .GetAsync();

            var notebook = notebooks.Where(x => x.Id == "1-abcdefgh-2364-4b40-8e33-c6ba539f98cd").FirstOrDefault();

            if (notebook != null)
            {
                var sections = await graphClient.Sites[site.Id]
                    .Onenote
                    .Notebooks[notebook.Id]
                    .Sections
                    .Request()
                    .GetAsync();

                var firstSection = sections.FirstOrDefault();

                if (firstSection != null)
                {
                    Console.WriteLine(firstSection.Self);
                } 
            }

`

謝謝,德莫特

我已按照上面的代碼深入到筆記本中,但無法構建共享點 URL。

我找到了這個問題的答案,而且比我預期的要簡單得多。 Sharepoint URL 存儲在 Links.OneNoteWebUrl 中的部分對象中。

希望這能讓其他人免於我在過去幾周所做的所有令人頭疼的事情。

var sections = await graphClient.Sites[site.Id]
.Onenote
.Notebooks[notebook.Id]
.Sections
.Request()
.GetAsync();

foreach (var section in sections)
{
    Console.WriteLine(section.DisplayName);
    Console.WriteLine(section.Links.OneNoteWebUrl.Href);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM