我正在尝试通过OneNote API创建新页面。我在跟踪Microsoft教程和文档。
看起来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.'
.... }发布于 2019-02-28 17:08:41
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-28 14:52:23
内容类型应该是Content-类型,类型中的大写字母'T‘。
https://stackoverflow.com/questions/54928010
复制相似问题