我正在尝试通过OneNote API创建新页面。我正在关注Microsoft tutorial和documentation。
似乎header()无法正常工作。
graph-tutorial \ 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;
}
route \ 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.'
.... }
最佳答案
header
方法采用两个字符串参数(“键”和“值”)。从SDK sample:
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);
关于javascript - Onenote API创建页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54928010/