Any way in OneNote API to extract link to another

2019-09-18 10:46发布

If we have a link to another OneNote page in the HTML content:

<a href="onenote:SectionB.one#Note1&amp;section-id={<section-id>}&amp;page-id={<page-id>}&amp;end&amp;base-path=https://<path>"

... before I write a parsing routine to extract that link, I thought I'd ask if I'd overlooked anything in the OneNote API to make this easier.

===========================================================================

[EDIT] Well, I've written my routine to extract the page-id of the linked note, but that page-id turns out to be quite different from the page-id that's returned as a property (id) of the linked note itself - and it doesn't work :(

Here's an example:

(1) page-id extracted from link: A8CECE6F-6AD8-4680-9773-6C01E96C91D0

(2) page-id as property of note:

0-5f49903893f048d0a3b1893ef004411f!1-240BD74C83900C17!124435

Vastly different, as you see. Accessing the page content via:

 ../pages/{page-id}/content

... for (1) returns nothing

... for (2) returns the full page content.

(The section-ids returned by both methods are also entirely different.)

So, how can I extract from the link a page-id that works?

1条回答
SAY GOODBYE
2楼-- · 2019-09-18 11:19

Unfortunately, the OneNote API currently does not support identifying links to other OneNote pages in page content. Links in OneNote can be links to anything: websites, other OneNote pages/sections/notebooks, network shares... The API does support getting links to pages by using

    GET ~/pages
    GET ~/sections/id/pages

The page metadata model contains a links object with the clientUrl and the webUrl.


Editing after your question update: You're right - the id in the link does not correspond to the id of the OneNote API. You can however compare the id in the link with the id in the OneNoteClientUrl exposed in the API. Here's an example of the response of a

    GET ~/sections/id/pages
    GET ~/pages

{ "title": "Created from WAC", "createdByAppId": "", "links": { "oneNoteClientUrl": { "href": "onenote:https://d.docs.live.net/29056cf89bb2d216/Documents/TestingNotification/Harrie%27s%20Section.one#Created%20from%20WAC&section-id=49b630fa-26cd-43fa-9c45-5c62d547ee3d&page-id=a60de930-0b03-4527-bf54-09f3b61d8838&end" }, "oneNoteWebUrl": { "href": "https://onedrive.live.com/redir.aspx?cid=29056cf89bb2d216&page=edit&resid=29056CF89BB2D216!156&parId=29056CF89BB2D216!105&wd=target%28Harrie%27s%20Section.one%7C49b630fa-26cd-43fa-9c45-5c62d547ee3d%2FCreated%20from%20WAC%7Ca60de930-0b03-4527-bf54-09f3b61d8838%2F%29" } }, "contentUrl": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162/content", "thumbnailUrl": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162/thumbnail", "lastModifiedTime": "2016-03-28T21:36:22Z", "id": "0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162", "self": "https://www.onenote.com/api/v1.0/me/notes/pages/0-a50842a9873945379f3d891a7420aa39!14-29056CF89BB2D216!162", "createdTime": "2016-03-24T20:38:16Z", "parentSection@odata.context": "https://www.onenote.com/api/v1.0/$metadata#me/notes/pages('0-a50842a9873945379f3d891a7420aa39%2114-29056CF89BB2D216%21162')/parentSection(id,name,self)/$entity", "parentSection": { "id": "0-29056CF89BB2D216!162", "name": "Harrie's Section", "self": "https://www.onenote.com/api/v1.0/me/notes/sections/0-29056CF89BB2D216!162" } }

You can also filter server side (if you want to save yourself from paging and regex's ;) ) for id's in the links by using:

    GET ~/pages?$filter=contains(links/oneNoteClientUrl/href,'a60de930-0b03-4527-bf54-09f3b61d8838')
查看更多
登录 后发表回答