通过图形 API 使用 OneNote 时,我遇到了许多问题。
我知道 OneNote 使用的不是直接的 html,他们需要为 API 来回转换它......但这似乎不是那么复杂的任务。
我正在处理内容中的标签,并且需要能够更新标签元素。除了我有一个有缩进的项目列表(p 或 li)标签之外,这都很好。
UPDATED
如果我的onenote中有这样的项目
没有嵌入图片的权利...所以这是链接
我点击 graph api 通过 graph api explorer 获取具有以下 url 的内容
GET - https://graph.microsoft.com/beta/users/myname/onenote/pages/0-c9861926a1e8080518ca3750afa63800!1-2B303C571455A20B!102505/content?includeIDs=true https://graph.microsoft.com/beta/users/myname/onenote/pages/0-c9861926a1e8080518ca3750afa63800!1-2B303C571455A20B!102505/content?includeIDs=true
返回的 html 将如下所示(请注意,缩进不存在)
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div id="div:{f115c5ea-0481-0f03-31aa-07b94321c323}{65}" style="position:absolute;left:264px;top:139px;width:624px">
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{67}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 1</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{71}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2a</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{73}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2b</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{76}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 3</p>
</div>
</body>
如果我修补那些具有像这样的子项目的项目以设置 ids(将 id 保留在那里...将其变成永久数据 id)以供以后更新甚至关闭标签:
PATCH - https://graph.microsoft.com/beta/users/myname/onenote/pages/0-c9861926a1e8080518ca3750afa63800!1-2B303C571455A20B!102505/content?includeIDs=true
[
{
'target':'p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}',
'action':'replace',
'content':'<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>'
}
]
将处理更新,然后内容将更新为:
图片在这里:
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div id="div:{f115c5ea-0481-0f03-31aa-07b94321c323}{65}" style="position:absolute;left:264px;top:139px;width:624px">
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{67}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 1</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{71}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2a</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{73}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2b</p>
<p id="p:{78cb2ca5-efec-4e6f-a763-12e9cac6a2b5}{2}" lang="en-US" data-tag="to-do" data-id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{74}" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>
<p id="p:{f115c5ea-0481-0f03-31aa-07b94321c323}{76}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 3</p>
</div>
</body>
对于嵌套的 ul/ol 项目,本质上也是如此……我也尝试替换整个列表而不是单个项目,但 api 调用错误,没有任何附加信息。嵌套项目符号列表似乎也丢失了父项目符号。
我尝试过对所有项目的所有更新进行批处理,一次执行一个,颠倒顺序。
有趣的是,如果我进行插入,则保留文本缩进和顺序,但没有删除/删除补丁来清除旧文本...例如
[
{
'target':'p:{56d579c0-1203-0224-0587-6fe03fb82539}{34}',
'action':'insert',
'position':'before',
'content':'<p data-id="My_own_id" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 1</p>'
},
{
'target':'p:{56d579c0-1203-0224-0587-6fe03fb82539}{34}',
'action':'<tried replace or delete/remove hoping it was undocumented>',
'content':'<tried blank or just a span>'
}
]
其他问题包括
- 表格失去显示网格线属性
- 如果我更新页面上的任何文本,没有文本的标签不会返回,甚至会消失
部分答案
这是非项目符号列表问题的部分答案...感谢代码为我指明了正确的方向。
通过在现有元素之前插入我的元素,它会保留顺序。
[
{
'target':'p:{20781e6d-ba99-4fca-9994-622720cad7f8}{249}',
'action':'insert',
'position':'before',
'content':'<p data-id="test" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Item 2</p>'
}
]
然后用以下命令删除旧的,看起来会保留格式。由于它是一个空 div OneNote 不会添加该元素。
[
{
'target':'p:{20781e6d-ba99-4fca-9994-622720cad7f8}{249}',
'action':'replace',
'content':'<div></div>'
}
]