gpt4 book ai didi

javascript - Onenote API 创建页面

转载 作者:行者123 更新时间:2023-11-30 06:18:07 24 4
gpt4 key购买 nike

我正在尝试通过 OneNote API 创建新页面。我正在关注 Microsoft tutorialdocumentation .

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.'
.... }

最佳答案

header 方法采用两个字符串参数(“Key”和“Value”)。来自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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com