2

我正在尝试通过 OneNote API 创建新页面。我正在关注Microsoft 教程文档

似乎 header() 不起作用。

图教程\graph.js:

createPage: async function(sectionID, content, accessToken) {
  const client = getAuthenticatedClient(accessToken);

  console.log('DEBUG:', '[Creating Pages]', sectionID);
  const res = await client
    .api(`/me/onenote/sections/${sectionID}/pages`)
    .header({
      'Content-type': 'application/xhtml+xml'
    })
    .post(content);

  return res;
}

路线\onenote.js:

let content = 
        `<!DOCTYPE html>
        <html>
          <head>
            <title>${subject}</title>
            <meta name="created" content="${creationDate}" />
          </head>
          <body>
            ${description}
          </body>
        </html>`

        let page = await graph.createPage(section.id, content, accessToken);

错误:

{ statusCode: 400,
  code: 'BadRequest',
  message: 'Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.'
  .... }
4

2 回答 2

1

header方法采用两个字符串参数(“Key”和“Value”)。从SDK 示例

client
    .api('/me')
    .header("content-type", "application/json")
    .update({
        "birthday": "1908-12-22T00:00:00Z"
    })
    .then((res) => {
        console.log("Updated my birthday");
    })
    .catch((err) => {
        console.log(err);
    });

在你的情况下,你想要:

const res = await client
  .api(`/me/onenote/sections/${sectionID}/pages`)
  .header('Content-type', 'application/xhtml+xml')
  .post(content);
于 2019-02-28T17:08:41.417 回答
-1

Content-type 应该是Content-Type ,Type中带有大写字母“T”。

于 2019-02-28T14:52:23.550 回答