【发布时间】:2018-09-27 17:13:02
【问题描述】:
我在通过图形 API 使用 OneNote 时遇到了一些问题。
我知道 OneNote 使用的不是直接的 html,他们需要为 API 来回转换它......但这似乎不是那么复杂的任务。
我正在处理内容中的标签,需要能够更新标签元素。没关系,除了我有一个项目列表(p 或 li)标签的地方有缩进。
更新
如果我的onenote中有这样的项目
我通过graph api explorer点击了graph api来获取以下url的内容
返回的 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>
如果我修补具有这样子项的那些以设置 id(将 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>'
}
]
其他问题包括
- 表格失去其显示网格线属性
- 如果我更新页面上的任何文本,没有文本的标签不会返回甚至消失
部分回答
这是非项目符号列表问题的部分答案...感谢 codeye 为我指明了正确的方向。
通过在现有元素之前插入我的元素,它会保留顺序。
[
{
'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>'
}
]
【问题讨论】:
-
请在描述中提供您这边的请求端点和请求正文。
-
我没有看到您描述的行为。您能否将链接或屏幕截图发布到示例页面?
-
在上面添加了更多细节......以及具体的网址和步骤。
-
感谢保罗。我想我知道发生了什么。
标签: microsoft-graph-api onenote-api