【问题标题】:Creating Classroom using App Script使用 App 脚本创建教室
【发布时间】:2017-05-10 09:09:45
【问题描述】:

我正在尝试使用应用脚本从电子表格创建 Google 教室。我可以成功创建课程,但它没有将课程资料(1 Doc)添加到关于页面。

这是我正在使用的代码,我尝试使用 API reference 无济于事。

有人可以告诉我如何正确格式化 courseMaterialSets 以包含我驱动器中的 Google Doc。

var create = Classroom.Courses.create({
"ownerId": '-My email address-',
  "name": getData[i][0],
  "section": getData[i][1],
  "descriptionHeading": getData[i][2],
  "description": getData[i][2],
    "courseMaterialSets" : [{
            "title" : 'Course Outline',
            "materials" : [{
                    "driveFile" : { 
                            "id" : getData[i][5],
                            "title" : 'Course Outline' ,
                            "alternateLink": getData[i][4], 
                            "thumbnailUrl" : 'https://drive.google.com/uc?export=download&id=-Image ID-',

                    },
                }
            ]
        }
    ]
})
}
Logger.log(create)
}

谢谢。

编辑

我更新了代码以反映 cmets 中的建议,并记录了 var create 的值,它返回了新创建的教室的所有信息,但没有提及课程材料集。

【问题讨论】:

  • Classroom.Courses.create({ "ownerId" : '-----@-----------', "name" : getData[i][0 ],“section”:getData[i][1],“descriptionHeading”:getData[i][2],“description”:getData[i][2],“courseMaterialSets”:[{“title”:字符串, “材料”:[{“驱动文件”:{{“id”:字符串,“标题”:字符串,“alternateLink”:字符串,“thumbnailUrl”:字符串,}},}]}]}); } }
  • 这是我从Classroom documentation 了解到的。抱歉重复评论,空间不足。
  • 你测试过上面的代码吗?我再次尝试使用该格式但没有成功。可以创建课程,但没有课程材料。

标签: javascript google-apps-script google-classroom


【解决方案1】:

According to the documentation 你必须使用 JSON 来specify the DriveFile object

"driveFile" : {
   "id":            theDocIdString,
   "title":         theDocTitleString,
   "alternateLink": urlToFileString,
   "thumbnailUrl":  imgThumbnailString 
   }

您当然可以从工作表中提取所有这些数据或使用变量来循环访问资源。

【讨论】:

  • 感谢您的回复,我再次尝试使用该格式,但没有成功。可以创建课程,但没有课程材料。
  • 您在运行程序时是否捕获并记录任何错误?没有更多信息,很难确定问题出在哪里。
  • 请看我的编辑。当我运行程序时,我没有收到任何错误。它成功完成并创建了教室,但没有将课程资料添加到 about 页面。
【解决方案2】:

这是我尝试成功创建课程的代码,但我也没有将课程资料附加到创建的 Google 课堂的“关于”选项卡上。

function createCourse() {
  var resource = {
    name: "XYZ course",
    room: "The Great Hall",
    ownerId: "me",
    courseMaterialSets: [{
      title: "course materials",
      materials: [
      {

        driveFile: {
          id: "insert id of google drive file" 

        }


      }
      ],
  }],
  }
  var newCourse = Classroom.Courses.create(resource);


}

我还尝试创建课程,然后在 Google Classroom 中接受课程并尝试添加教室集。这也没有成功。

function addClassSet() {
  var id = "course id obtained with sample script in documentation";
  var resource = {
    name: "XYZ course",
    room: "The Great Hall",
    courseMaterialSets: [{
      title: "course materials",
      materials: [
      {

        driveFile: {
          id: "drive file id" //drive file was not added

        }


      }
      ],
  }],
    description: "This is a trial course", //this worked
  }
  Classroom.Courses.update(resource, id);
}

是不是因为documentation states courseMaterialsSets 是只读的???

【讨论】:

  • 我相信Brian 上面所说的是正确的。仅提供 id 参数是不够的,您必须提供 JSON 对象中的所有参数(我还没有测试过)。文档的那部分与资源对象有关,即从现有类中检索信息,这就是它说“只读”的原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多