课堂服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Classroom 服务,您可以在 Apps 脚本中使用 Google Classroom API。借助此 API,管理员、教师和学生可以查看和管理课程及课程表。
参考
如需详细了解此服务,请参阅 Google Classroom API 的参考文档。与 Apps 脚本中的所有高级服务一样,Classroom 服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅方法签名是如何确定的。
如需报告问题并寻求其他支持,请参阅 Google 课堂支持指南。
示例代码
以下示例代码使用 API 的版本 1。
列出课程
此示例列出了用户有权访问的前 10 门课程。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Google Classroom API within Apps Script allows admins, teachers, and students to manage courses and rosters.\u003c/p\u003e\n"],["\u003cp\u003eThis is an advanced service requiring prior enabling and provides functionalities mirroring the public API.\u003c/p\u003e\n"],["\u003cp\u003eComprehensive documentation, support resources, and sample code are available for guidance and troubleshooting.\u003c/p\u003e\n"],["\u003cp\u003eYou can find sample code demonstrating functionalities like listing the user's accessible courses.\u003c/p\u003e\n"]]],[],null,["# Classroom Service\n\nThe Classroom service allows you to use the\n[Google Classroom API](/classroom) in Apps Script. This API gives admins,\nteachers, and students the ability to view and manage their courses and rosters.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced). Follow along with the [quickstart](/classroom/quickstart/apps-script) for step-by-step instructions on how to get started.\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/classroom/reference/rest) for the Google Classroom API.\nLike all advanced services in Apps Script, the Classroom service uses the same\nobjects, methods, and parameters as the public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Classroom support guide](/classroom/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/classroom/reference/rest) of the API.\n\n### List courses\n\nThis sample lists the first ten courses the user has access to. \nadvanced/classroom.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/classroom.gs) \n\n```javascript\n/**\n * Lists 10 course names and IDs.\n */\nfunction listCourses() {\n /**\n * @see https://developers.google.com/classroom/reference/rest/v1/courses/list\n */\n const optionalArgs = {\n pageSize: 10\n // Use other query parameters here if needed.\n };\n try {\n const response = Classroom.Courses.list(optionalArgs);\n const courses = response.courses;\n if (!courses || courses.length === 0) {\n console.log('No courses found.');\n return;\n }\n // Print the course names and IDs of the available courses.\n for (const course in courses) {\n console.log('%s (%s)', courses[course].name, courses[course].id);\n }\n } catch (err) {\n // TODO (developer)- Handle Courses.list() exception from Classroom API\n console.log('Failed with error %s', err.message);\n }\n}\n```"]]