Send Email with all new OneNote entries

2019-09-04 12:27发布

I use Microsoft OneNote daily to take notes. I would like to write a script to send myself an email every night with all the new notes I took that day across notebooks so I can review them. This would usually be straightforward in e.g. a Word doc where I can timestamp all saves and take the latest file, diff it with the last file from the previous day and send the diff. Unfortunately OneNote complicates this for at least two reasons:

  1. OneNote autosaves and as far as I can tell does not offer the ability to rename saves or add a timestamp to the filename
  2. Notebooks and pages mean changes are across "documents" instead of a single file that can be diff'd.

So I am looking for a solution that considers the complications above. Thanks.

标签: onenote
1条回答
\"骚年 ilove
2楼-- · 2019-09-04 12:58

The basic approach via the microsoft-graph API

./me/onenote/pages?$filter=lastModifiedDateTime ge yyyy-MM-ddThh:mm:ssZ&$expand=parentNotebook

will yield json data with
title - Page title
links/oneNoteWebUrl - allows opening of the onenote page in web browser
links/oneNoteClientUrl - allows opening of the onenote page in onenote app
parentNotebook/displayName - Notebook name
self - needed to get page content.
for small page numbers this may work but is likely to time out with a 504 error for a drive with many pages.

In that case a two stage approach is required.

./me/onenote/sections?$filter=lastModifiedDateTime ge yyyy-MM-ddThh:mm:ssZ

will return a list of all the sections that have been modified since the defined lastModifiedDateTime.

Next iterate through the returned json data and get pages modified since lastModifiedDateTime with the returned pagesUrls using the format

.me/onenote/sections/1-xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx/pages?$filter=lastModifiedDateTime ge yyyy-MM-ddThh:mm:ssZ&$expand=parentNotebook

yielding the same data as noted previously.
Once you have this data you can generate an email containing a list of the modified Notebooks,page names and page links.

If you need the actual page data(content) then you need to call

./me/onenote/pages/1-1c13bcbae2fdd747a95b3e5386caddf1!1-xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx/content?includeIDs=true&includeInkML=true&preAuthenticated=true

Which will give you text/html, ink and links to other resources from each page.

查看更多
登录 后发表回答