/**
* Lists 10 course names and ids.
*/
function listCourses() {
/** here pass pageSize Query parameter as argument to get maximum number of result
* @see https://developers.google.com/classroom/reference/rest/v1/courses/list
*/
const optionalArgs = {
pageSize: 10
// Use other parameter here if needed
};
try {
// call courses.list() method to list the courses in classroom
const response = Classroom.Courses.list(optionalArgs);
const courses = response.courses;
if (!courses || courses.length === 0) {
console.log('No courses found.');
return;
}
// Print the course names and IDs of the courses
for (const course of courses) {
console.log('%s (%s)', course.name, course.id);
}
} catch (err) {
// TODO (developer)- Handle Courses.list() exception from Classroom API
// get errors like PERMISSION_DENIED/INVALID_ARGUMENT/NOT_FOUND
console.log('Failed with error %s', err.message);
}
}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-23。"],[[["This quickstart guide demonstrates how to create a Google Apps Script that interacts with the Google Classroom API to list courses."],["Before running the script, you need a Google for Education account, access to Google Drive, and must enable the Google Classroom API within the script."],["The script retrieves and displays the names and IDs of up to 10 courses from your Google Classroom account, requiring authorization upon its first execution."],["For production environments, refer to the provided resources for authentication, authorization, and troubleshooting guidance."],["Users can explore further by consulting the advanced services documentation, troubleshooting guide, and the Classroom API reference."]]],[]]