OneNote API : 最顶层对象的 PATCH 请求

OneNote API : PATCH request for topmost object

我正在想办法更新我的页面 - 我需要始终替换 <body> 标签内的所有内容。

OneNote API 说:

The following elements do not support any PATCH actions: - img or object (absolutely positioned) - meta, head - tr, tda, span, any style tags

Note: Absolutely positioned div, img, or object elements are direct children of the page body that define style=position:absolute.

好的,这很清楚。所以我无法替换没有 ID 的 <object>,因为如果它没有 ID,它要么应该是 <div> 的一部分,要么属于最顶层的 div。

这是我页面的内容:

<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
    <title>image and PDF 2</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
    <div id="div:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{32}" data-id="_default" style="position:absolute;left:48px;top:120px;width:624px">
        <p id="p:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{38}" style="margin-top:2.8pt;margin-bottom:2.8pt"> SOME TEXT HERE <br />
        </p>
        <object data-attachment="pdf-sample.pdf" type="application/pdf" data="https://www.onenote.com/api/v1.0/me/notes/resources/0-3329938c15524891836ef46f570c17ce!1-6481EB8A1188E91C!389/$value" />
        <img id="img:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{42}" alt="Image" src="https://www.onenote.com/api/v1.0/me/notes/resources/0-dfd3e39146d4425b974a71479787845f!1-6481EB8A1188E91C!389/$value" data-src-type="image/jpeg" data-fullres-src="https://www.onenote.com/api/v1.0/me/notes/resources/0-dfd3e39146d4425b974a71479787845f!1-6481EB8A1188E91C!389/$value" data-fullres-src-type="image/jpeg" />
        <object data-attachment="_SaferoomTestDOC.doc" type="application/msword" data="https://www.onenote.com/api/v1.0/me/notes/resources/0-07e77c13690247e88afcd20af3b45a12!1-6481EB8A1188E91C!389/$value" />
    </div>
  </body>
</html>

现在,如果我想替换上面的图像 (<img>),我会这样做:

 {
'target':'img:{cfaf2831-c9e3-4b68-99ac-c4fc0bac0937}{42}',
'action':'replace',
'content':'<img src="NEW IMAGE" alt="NEW IMAGE" />'

},

但是如何替换我的对象是 PDF 或 Word 文档? 以及如何替换整个 <body>?

P.S。我试过将 <object> 对象标签包装到 div 中,<div> 标签在上传时被删除。

P.P.S。我总是需要替换正文中的全部内容以及所有对象和图像。

But how do I replace the object which in my case is a PDF or Word document? And how do I replace the whole ?

在这种情况下,我们可以删除旧页面并创建新页面。下面是一个创建页面的示例,页面中嵌入了文字和图像:

POST https://www.onenote.com/api/v1.0/me/notes/pages
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
Authorization: Bearer {token}

---------------------------acebdf13572468
Content-Disposition:form-data; name="Presentation"
Content-Type:text/html

<!DOCTYPE html>
<html>
  <head>
    <title>A page with rendered images and an attached file</title>
    <meta name="created" content="2016-05-30T07:30:00-08:00" />
  </head>
  <body>
    <p>Here's an image from an <i>online source</i>:</p>
    <img src="http://png-4.findicons.com/files/icons/2795/office_2013_hd/2000/onenote.png" alt="an image on the page" width="500" />
    <p>Here's an image uploaded as <b>binary data</b>:</p>
    <img src="name:imageBlock1" alt="an image on the page" width="300" />
    <p>Here's a file attachment:</p>
    <object data-attachment="doc1.docx" data="name:fileBlock1" type="application/docx" />
  </body>
</html>

---------------------------acebdf13572468
Content-Disposition: form-data; name="imageBlock1"; filename="wdIcon.jpg"
Content-Type: image/jpeg

<@INCLUDE *C:\users\username\desktop\wdIcon.jpg*@>
---------------------------acebdf13572468
Content-Disposition: form-data; name="fileBlock1"; filename="doc1.docx"
Content-Type: application/msword

<@INCLUDE *C:\users\username\desktop\doc1.docx*@>
---------------------------acebdf13572468—

要替换整个正文(技术上只是正文标签的第一个直接子 div),请使用:

{
 'target':'body',
 'action':'replace',
 'content':'your new page content'
}