2025年5月4日日曜日

Google Classroom APIで質問(選択式)を作成してみる


Classroom で記述式の質問を作成する API を試してみました


Classroomの画面上では「授業 > 作成 > 質問 > 選択式」で作成できます




Code.gs
function createMultipleChoiceQuestion() {
const courseId = '776967326029'; // クラスID

const question = {
title: 'Who are you learning for?',
description: 'Please select the option that best describes your motivation.',
workType: 'MULTIPLE_CHOICE_QUESTION',
state: 'DRAFT',
multipleChoiceQuestion: {
choices: ['For your students', 'For your co-teachers', 'For yourself', 'Other']
}
};

try {
const created = Classroom.Courses.CourseWork.create(question, courseId);
Logger.log(`質問作成成功: ID = ${created.id}, タイトル: ${created.title}`);
} catch (e) {
Logger.log('質問作成失敗: ' + e.message);
}
}


実行後には以下のような選択式の質問が下書きで作成されます
画面右上の青いボタン「質問を作成」するとクラスに公開されます




生徒は割り当てられた質問の回答を選択して「提出」します


Reference