Is there an example of the Classroom.Courses.Topics.get so I can call Classroom.Courses.CourseWork.create with an existing topicId?

做~自己de王妃 提交于 2020-07-10 08:35:46

问题


Our school is trying to move all coursework online. We have eight teachers adding content to one class, mostly manually rather than with a script. I have a javascript script that creates Coursework based on rows of a spreadsheet. If possible, I would like to have the topic as a string in each row of the spreadsheet of Coursework data, e.g. "Math Week 1", use Classroom.Courses.Topics.get to get the topic, then write the topicId from the topic into CourseWork.

I found code on StackOverflow to create a topic. I've tried many variations of Classroom.Courses.Topics.get but always get the error Requested entity was not found. (line 14, file "createTopics") Here are some of the methods I've tried: I previously created "fakeTopic3: using Classroom.Courses.Topics.create

   var topicName = "fakeTopic3";
   var getTopic2= Classroom.Courses.Topics.get(courseId,{name:topicName} )
   var getTopic= Classroom.Courses.Topics.get(courseId,topicName )
   var getTopic = Classroom.Courses.Topics.get({name:topicName},courseId );
   var getTopic = Classroom.Courses.Topics.get(topicName,courseId );

回答1:


Answer:

You need to use courses.topics.list[1] with the course ID to get a list of the topic IDs and then use the topic ID rather than the topic name in the courses.topics.get[2] call.

More Information:

As explained in the documentation for the courses.topics.get method:

The request body must be empty.

So you need to supply only the course ID and the topic ID.

Example Code:

var coursesList = Classroom.Courses.list();
var topicName = "your topic's name";
var courseId = "your course's ID";
  
for (var i = 0; i < coursesList.courses.length; i++) {
  if (coursesList.courses[i].name == topicName) {
    var topicId = coursesList.courses[i].id;
    break;
  }    
}

var getTopic = Classroom.Courses.Topics.get(courseId. topicId);    

I hope this is helpful to you!

References:

  1. Method: courses.topics.list
  2. Method: courses.topics.get


来源:https://stackoverflow.com/questions/60724676/is-there-an-example-of-the-classroom-courses-topics-get-so-i-can-call-classroom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!