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

2025年4月29日火曜日

Google ClassroomのAPIで課題の情報を取得したい


Classroom に作成した課題の情報を API で取得したくて試したコードです


下記 Code.gs の courseId と courseWorkId を自身の環境に合わせて書き換えて

getFullCourseWorkInfo() を実行すると

実行結果のように課題の情報が取得できます



Code.gs
function getFullCourseWorkInfo() {
const courseId = "699141862609"; // あなたのクラスID
const courseWorkId = "776129368220"; // あなたの課題ID

try {
const courseWork = Classroom.Courses.CourseWork.get(courseId, courseWorkId);
const jsonOutput = JSON.stringify(courseWork, null, 2); // 整形してJSON文字列に変換
Logger.log('課題情報取得成功!');
Logger.log(jsonOutput);
} catch (e) {
Logger.log('課題情報取得失敗: ' + e.message);
}
}


実行結果
{
  "creatorUserId": "1234567890",
  "state": "DELETED",
  "associatedWithDeveloper": true,
  "workType": "ASSIGNMENT",
  "assigneeMode": "ALL_STUDENTS",
  "updateTime": "2025-04-27T07:38:17.991Z",
  "title": "30-Second Self-Introduction Transcript",
  "alternateLink": "https://classroom.google.com/c/Njk5MTQxODYyNjA5/a/Nzc2MTI5MzY4MjIw/details",
  "dueTime": {
    "hours": 23,
    "minutes": 59
  },
  "dueDate": {
    "day": 10,
    "year": 2025,
    "month": 5
  },
  "courseId": "699141862609",
  "maxPoints": 10,
  "description": "In our first class, you will introduce yourself in English for 30 seconds.\n\nBefore the class, please prepare what you want to say.\nWrite a short script (transcript) in a Google Document and submit it.\n\nInstructions:\n- Write your introduction in English.\n- Make it short enough to speak in about 30 seconds (around 70–90 words).\n- Use a Google Document for your writing.\n\nDeadline:\n- Please submit it before the day of our first class.\n\nNote:\n- You do not need to memorize everything exactly.\n- Try to speak naturally by practicing with your script.",
  "submissionModificationMode": "MODIFIABLE_UNTIL_TURNED_IN",
  "creationTime": "2025-04-27T07:34:49.146Z",
  "id": "776129368220",
  "assignment": {
    "studentWorkFolder": {
      "id": "1234567890abcdefghijklmnopqrstuvwxyz"
    }
  }
}


この課題はすでに削除済みのため state は DELETED になっています



Reference

Method: courses.courseWork.get

Resource: CourseWork


Latest post

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

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