将云端硬盘文件附加到 Google 课堂 API 的作业
Attaching a Drive file to an assignment with Google Classroom API
使用 Google Apps 脚本我已经成功地使用以下代码创建了一个作业:
Classroom.Courses.CourseWork.create({
"courseId": id,
"title" : title,
"description" : desc,
"workType" : 'ASSIGNMENT',
}, id)
这很好用,正在创建课堂作业草稿。但是,当我尝试像这样附加一个云端硬盘文件时:
Classroom.Courses.CourseWork.create({
"courseId": id,
"title" : title,
"description" : desc,
"workType" : 'ASSIGNMENT',
"materials" : [
{
"driveFile": {
"id" : fileId,
"title" : fileTitle,
"alternateLink" : fileLink,
"thumbnailUrl" : fileThumbnail,
},
"shareMode" : 'STUDENT_COPY',
}
],
}, id)
我收到这些错误:
执行失败:收到无效的 JSON 负载。 'course_work.materials[0]' 处的未知名称 "share_mode":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "alternate_link":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "id":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "title":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "thumbnail_url":找不到字段。 (第 61 行,文件 "Classroom")[总运行时间 1.187 秒]
任何帮助将不胜感激,谢谢
你可以参考这个。此错误可能是由于请求格式错误造成的。
示例代码:
function myFunction() {
var ClassSource = {
title: "Test File",
state: "DRAFT",
materials: [
{
driveFile:{
driveFile: {
id: "fileID",
title: "Sample Document"
},
shareMode: "STUDENT_COPY"
}
}
],
workType: "ASSIGNMENT"
};
Classroom.Courses.CourseWork.create(ClassSource, COURSEID)
//Logger.log(exec);
}
您可以尝试使用 Try this API。
希望对您有所帮助!
使用 Google Apps 脚本我已经成功地使用以下代码创建了一个作业:
Classroom.Courses.CourseWork.create({
"courseId": id,
"title" : title,
"description" : desc,
"workType" : 'ASSIGNMENT',
}, id)
这很好用,正在创建课堂作业草稿。但是,当我尝试像这样附加一个云端硬盘文件时:
Classroom.Courses.CourseWork.create({
"courseId": id,
"title" : title,
"description" : desc,
"workType" : 'ASSIGNMENT',
"materials" : [
{
"driveFile": {
"id" : fileId,
"title" : fileTitle,
"alternateLink" : fileLink,
"thumbnailUrl" : fileThumbnail,
},
"shareMode" : 'STUDENT_COPY',
}
],
}, id)
我收到这些错误:
执行失败:收到无效的 JSON 负载。 'course_work.materials[0]' 处的未知名称 "share_mode":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "alternate_link":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "id":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "title":找不到字段。
收到无效的 JSON 负载。 'course_work.materials[0].drive_file' 处的未知名称 "thumbnail_url":找不到字段。 (第 61 行,文件 "Classroom")[总运行时间 1.187 秒]
任何帮助将不胜感激,谢谢
你可以参考这个
示例代码:
function myFunction() { var ClassSource = { title: "Test File", state: "DRAFT", materials: [ { driveFile:{ driveFile: { id: "fileID", title: "Sample Document" }, shareMode: "STUDENT_COPY" } } ], workType: "ASSIGNMENT" }; Classroom.Courses.CourseWork.create(ClassSource, COURSEID) //Logger.log(exec); }
您可以尝试使用 Try this API。
希望对您有所帮助!