Apps Scriptリファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary

2025年4月25日金曜日

Google Classroom API で利用できるサービスやメソッドを知りたい


Apps Scriptで利用する Classroom API は SpreadsheetApp や DocumentApp と違って、外部サービスとして明示的にサービスへ追加しないと使えません


そのためか、公式のリファレンスでは、Sheets, Docs のように Apps Script で書かれた例が少ないようです



この記事を執筆時点では Classroom にまだあまり詳しくないので、とりあえず以下のようなサイトを見ていますが、API で何ができて何ができないのか把握するのにちょっと時間がかかりそうです


Classroom Service


Develop Google Classroom apps and integrations


Google Classroom API
https://developers.google.com/workspace/classroom/reference/rest


Discovery document
https://classroom.googleapis.com/$discovery/rest?version=v1





Classroom API で利用できるサービスやメソッドについてはスクリプトエディタで候補を出してくれますが、これの一覧がほしいと思いました


ChatGPT や Gemini などで都度コードを生成してもらってもいいのですが、ある程度は自分の頭に入れていろいろ想像したり試してみたい気持ちもあったりする


コードでそういう一覧を出力できないか試してみたところ、以下のように書くと出力できました

(出力しただけでまだ検証はしていないので、実際に使えるかは今後の記事で試してみようと思っています)



Code.gs
function listClassroomMethods() {
let output = "";
const services = Object.keys(Classroom);
services.forEach(service => {
output += 'Service: ' + service + "\n";
const methods = Object.keys(Classroom[service])
.filter(key => typeof Classroom[service][key] === 'function');
methods.forEach(method => {
output += ' Method: ' + method + "\n";
});

// さらに階層を調べる(例:Courses.CourseWork など)
const subServices = Object.keys(Classroom[service])
.filter(key => typeof Classroom[service][key] === 'object');
subServices.forEach(subService => {
output += ' Sub-service: ' + subService + "\n";
const subMethods = Object.keys(Classroom[service][subService])
.filter(key => typeof Classroom[service][subService][key] === 'function');
subMethods.forEach(subMethod => {
output += ' Method: ' + subMethod + "\n";
});
});
});
console.log(output)
}



実行結果
Service: toString
Service: getVersion
Service: newModifyAttachmentsRequest
Service: newCopyHistory
Service: newCloudPubsubTopic
Service: newModifyCourseWorkAssigneesRequest
Service: newRegistration
Service: newTeacher
Service: newCourseWorkMaterial
Service: newAddOnAttachment
Service: newStudent
Service: newStateHistory
Service: newUserProfile
Service: newTopic
Service: newGuardianInvitation
Service: newCourseMaterialSet
Service: newCourseWorkChangesInfo
Service: newAttachment
Service: newDate
Service: newInvitation
Service: newReclaimStudentSubmissionRequest
Service: newAssignmentSubmission
Service: newDriveFolder
Service: newReturnStudentSubmissionRequest
Service: newAssignment
Service: newGradingPeriod
Service: newFeed
Service: newEmbedUri
Service: newModifyAnnouncementAssigneesRequest
Service: newCourse
Service: newMultipleChoiceQuestion
Service: newMultipleChoiceSubmission
Service: newName
Service: newCourseMaterial
Service: newRubric
Service: newTurnInStudentSubmissionRequest
Service: newLevel
Service: newDriveFile
Service: newGlobalPermission
Service: newGradeCategory
Service: newYouTubeVideo
Service: newLink
Service: newGradingPeriodSettings
Service: newTimeOfDay
Service: newAnnouncement
Service: newGradebookSettings
Service: newGradeHistory
Service: newIndividualStudentsOptions
Service: newSharedDriveFile
Service: newShortAnswerSubmission
Service: newMaterial
Service: newModifyIndividualStudentsOptions
Service: newCourseRosterChangesInfo
Service: newSubmissionHistory
Service: newCriterion
Service: newCourseAlias
Service: newAddOnAttachmentStudentSubmission
Service: newCourseWork
Service: newForm
Service: newStudentSubmission
Service: Courses
Method: toString
Method: patch
Method: get
Method: create
Method: updateGradingPeriodSettings
Method: update
Method: getGradingPeriodSettings
Method: list
Method: remove
Sub-service: Aliases
Method: toString
Method: create
Method: list
Method: remove
Sub-service: Announcements
Method: toString
Method: patch
Method: getAddOnContext
Method: get
Method: create
Method: list
Method: modifyAssignees
Method: remove
Sub-service: CourseWork
Method: toString
Method: patch
Method: updateRubric
Method: getAddOnContext
Method: get
Method: create
Method: list
Method: modifyAssignees
Method: remove
Sub-service: CourseWorkMaterials
Method: toString
Method: patch
Method: getAddOnContext
Method: get
Method: create
Method: list
Method: remove
Sub-service: Posts
Method: toString
Method: getAddOnContext
Sub-service: Students
Method: toString
Method: get
Method: create
Method: list
Method: remove
Sub-service: Teachers
Method: toString
Method: get
Method: create
Method: list
Method: remove
Sub-service: Topics
Method: toString
Method: patch
Method: get
Method: create
Method: list
Method: remove
Service: Invitations
Method: toString
Method: get
Method: create
Method: list
Method: remove
Method: accept
Service: Registrations
Method: toString
Method: create
Method: remove
Service: UserProfiles
Method: toString
Method: get
Sub-service: GuardianInvitations
Method: toString
Method: patch
Method: get
Method: create
Method: list
Sub-service: Guardians
Method: toString
Method: get
Method: list
Method: remove



Tips

一覧を出力するコードはChatGPTが書いてくれました
出力の形をちょっと修正したのが上記のCode.gsです



追記

いろいろ調べているうちに
Google の API をブラウザ上で試せる環境があることを知りました

このサイトでそれぞれの API で利用できる機能の一覧を見ながら
実際に試すことができます




ちなみに

Classroom の Reference を見ながら API を試すこともできます



Reference


Develop Google Classroom apps and integrations



Google API Explorer > Classroom API

Latest post

Google Classroom API でクラスの一覧を取得したい

自分が指導・参加しているクラスの名称とIDを取得するコードを試しました 下記 Code.gs では pageSize で 100 を設定していますが 必ず 100件 返ってくるとは限らないらしいです https://developers.google.com/workspace/...