Node.js 谷歌教室.create的正确JSON格式是什么?
我正在尝试使用谷歌教室API创建一个教室。无论何时运行教室.create函数,我都会收到相同的错误消息。我正在使用他们文档中的JSON格式,但我就是无法让它工作。我想我一定错过了什么 这就是功能:Node.js 谷歌教室.create的正确JSON格式是什么?,node.js,json,google-api,google-classroom,Node.js,Json,Google Api,Google Classroom,我正在尝试使用谷歌教室API创建一个教室。无论何时运行教室.create函数,我都会收到相同的错误消息。我正在使用他们文档中的JSON格式,但我就是无法让它工作。我想我一定错过了什么 这就是功能: async function listCourses(auth) { const classroom = google.classroom({ version: 'v1', auth }); //Read data from JSON let data = fs.readFileSync("
async function listCourses(auth) {
const classroom = google.classroom({ version: 'v1', auth });
//Read data from JSON
let data = fs.readFileSync("class.json");
let course = JSON.parse(data);
//Try and create course
try {
const res = await classroom.courses.create(course);
console.log(res.data);
}
catch (error) {
console.log(error)
}
//List all current courses
classroom.courses.list({
pageSize: 10,
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
const courses = res.data.courses;
if (courses && courses.length) {
console.log('Courses:');
courses.forEach((course) => {
console.log(`${course.name} (${course.id})`);
});
} else {
console.log('No courses found.');
}
});
}
这是JSON:
{
"id": "157942918368",
"name": "English - 9Y",
"section": "Period 2",
"ownerId": "me",
"courseState": "ACTIVE"
}
这是错误消息:
code: 400,
errors: [
{
message: `Invalid JSON payload received. Unknown name "name": Cannot bind query parameter. Field 'name' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "ownerId": Cannot bind query parameter. Field 'ownerId' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "courseState": Cannot bind query parameter. Field 'courseState' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "id": Cannot bind query parameter. Field 'id' could not be found in request message.\n` +
`Invalid JSON payload received. Unknown name "section": Cannot bind query parameter. Field 'section' could not be found in request message.`,
reason: 'invalid'
}
]我相信你的目标如下
- 您想使用googleapis for Node.js创建新课程
- 在googleapis for Node.js中,请将请求正文放在
和/或资源
中。请求正文
- 我认为您的错误消息的原因是由于这一点
- 当使用
时,“id:”157942918368“,
发生请求错误包含无效参数。
- 当使用
时,出现“courseState”:“ACTIVE”
。“@CourseStateDenied错误,该用户无法创建课程或将课程转换到请求的状态。”
- 在这种情况下可以使用“PROVISIONED”
- 在这个修改中,它假设您的
可用于使用courses.create in-classification API的方法const-chorscheck=google.chorscheck({version:'v1',auth})
- 您想使用googleapis for Node.js创建新课程
- 在googleapis for Node.js中,请将请求正文放在
和/或资源
中。请求正文
- 我认为您的错误消息的原因是由于这一点
- 当使用
时,“id:”157942918368“,
发生请求错误包含无效参数。
- 当使用
时,出现“courseState”:“ACTIVE”
。“@CourseStateDenied错误,该用户无法创建课程或将课程转换到请求的状态。”
- 在这种情况下可以使用“PROVISIONED”
- 在这个修改中,它假设您的
可用于使用courses.create in-classification API的方法const-chorscheck=google.chorscheck({version:'v1',auth})
- 我相信你的目标如下
const res = await classroom.courses.create(course);
const res = await classroom.courses.create({ requestBody: course });
const res = await classroom.courses.create({ resource: course });
{
"id": "157942918368",
"name": "English - 9Y",
"section": "Period 2",
"ownerId": "me",
"courseState": "ACTIVE"
}
{
"name": "English - 9Y",
"section": "Period 2",
"ownerId": "me",
}