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

时间:2016-05-27 19:33:05

标签: objective-c onenote office365-restapi

我想知道如何更新我的页面 - 我需要始终替换<body>标记内的所有内容。

OneNote API说:

  

以下元素不支持任何PATCH操作:    - img或object(绝对定位)    - 元,头    - tr,tda,span,任何样式标签

     

注意:绝对定位的div,img或object元素是定义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。我总是需要替换身体内的所有内容以及所有对象和图像。

2 个答案:

答案 0 :(得分:1)

  
    

但是如何替换在我的情况下是PDF或Word文档的对象?我该如何更换整个?

  

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

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—

答案 1 :(得分:0)

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

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