问题
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:
- Method: courses.topics.list
- Method: courses.topics.get
来源:https://stackoverflow.com/questions/60724676/is-there-an-example-of-the-classroom-courses-topics-get-so-i-can-call-classroom