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

ラベル Google Classroom の投稿を表示しています。 すべての投稿を表示
ラベル Google Classroom の投稿を表示しています。 すべての投稿を表示

2025年5月7日水曜日

Google Formsで1〜5段階評価の質問を作りたい


Googleフォームで1〜5段階評価の質問を作る場合は

質問の種類を「均等目盛」にします


フォームの編集画面

段階は「0」から「10」まで設定できます


今回は評価1が「Beginner」で評価5が「Expert」として作成しています


フォームの回答画面




Apps Script で作成する場合

以下の Code.gs で formName, description, title, min, max, leftLabel, rightLabel の値を書き換えて

createScaleQuestion() を実行すると

編集用のURLがログに出力されます



Code.gs
function createScaleQuestion() {
const formName = 'Google Forms Proficiency Survey';
const description = 'Please rate your Google Forms proficiency.';
const title = 'How proficient are you with Google Forms?';
const min = 1;
const max = 5;
const leftLabel = 'Beginner';
const rightLabel = 'Expert';

// Create the form
const form = FormApp.create(formName);
form.setDescription(description);

// Add scale question
const item = form.addScaleItem();
item.setTitle(title)
.setBounds(min, max)
.setLabels(leftLabel, rightLabel)
.setRequired(false);

form.setPublished(false);

Logger.log('Form Edit URL: ' + form.getEditUrl());
}





Tips

Beginner, Expert などのラベルは省略可能です

フォームの編集画面



フォームの回答画面



Reference

addScaleItem() 
setLabels(lower, upper) 

setBounds(lower, upper) 


2025年5月4日日曜日

Google Classroom APIでクラス内にある課題を取得してみる


Classroomの授業の中にある「課題」を取得してみたときのコードです

今回は授業の中に「課題」「テスト付きの課題」「質問」「資料」が保存されている状態で実行してみます


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

listAllCourseWorkAssignments() を実行すると

PUBLISHED または DRAFT 状態の「課題」と

「テスト付きの課題」のタイトル, ID, 状態がログに出力されます




Code.gs
function listAllCourseWorkAssignments() {
const courseId = '776967326029'; // クラスIDを指定

const courseWorkList = Classroom.Courses.CourseWork.list(courseId, {
courseWorkStates: ['PUBLISHED', 'DRAFT']
});
Logger.log('=== 課題(CourseWork) ===');
if (courseWorkList.courseWork) {
courseWorkList.courseWork.forEach(work => {
Logger.log(`タイトル: ${work.title}, ID: ${work.id}, 状態: ${work.state}`);
});
} else {
Logger.log('課題はありません。');
}
}




Tips

「テスト付きの課題」は現状 API 経由では作成できなかったため

 Classroom の画面上で追加しました


作成したサンプルを下書きで保存しています



ちなみに「テスト付きの課題」は
英語版では「Quiz assignment」です



「テスト付きの課題」はClassroomの画面上では「課題」と区別されていますが

APIではどちらも同じ CourseWorkType である ASSIGNMENT として扱われています

そのためAPIを利用して取得する場合は

「テスト付きの課題」も「課題」として取得されるようです

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

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


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


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



Code.gs の courseId, title, description を自身の環境に合わせて書き換えて

createShortAnswerQuestion() を実行すると


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

const question = {
title: 'What drives you to learn Google Classroom?',
description: 'Please describe your motivation for learning Google Classroom in about 50 words.',
workType: 'SHORT_ANSWER_QUESTION',
state: 'DRAFT'
};

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


実行後には以下のような記述式の質問が下書きで作成されます

画面右上の青いボタン「質問を作成」するとクラスに公開されます




生徒は割り当てられた質問に自分の回答を入力して「提出」します




Reference

Method: courses.courseWork.create

CourseWorkType

Create a question

Answer a question

2025年5月2日金曜日

Google Classroom APIでクラス内にある資料を取得してみる


Classroomの授業の中にある「資料」を取得してみたときのコードです

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

listAllCourseWorkMaterials() を実行すると

PUBLISHED または DRAFT 状態の「資料」のタイトル, ID, 状態がログに出力されます



Code.gs
function listAllCourseWorkMaterials() {
const courseId = '776967326029'; // クラスIDを指定
const materialsList = Classroom.Courses.CourseWorkMaterials.list(courseId, {
courseWorkMaterialStates: ['PUBLISHED', 'DRAFT']
});

if (!materialsList.courseWorkMaterial || materialsList.courseWorkMaterial.length === 0) {
Logger.log('このクラスには資料がありません。');
return;
}

materialsList.courseWorkMaterial.forEach(material => {
Logger.log(`タイトル: ${material.title}, ID: ${material.id}, 状態: ${material.state}`);
});
}



Reference

Method: courses.courseWorkMaterials.list

Google Classroom APIで資料を作成してみる


指定したクラスに資料を作成するコードを試してみました


Classroomの画面上では「授業 > 作成 > 資料」で作れます



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

createMaterial() を実行すると

courseId で指定したクラスに資料が作成されます

今回は Syllabus を想定して書いてみたので description がちょっと長くなりました



Code.gs
function createMaterial() {
const courseId = '776967326029'; // クラスIDを指定
const title = 'Syllabus';
const description = `
Course Title:
Google Classroom Essentials

Department / Program:
EdTech Training Program

Term / Schedule:
Online, Self-paced

Classroom / Location:
Online, from the comfort of your home

Instructor:
Pre-Practice

Course Overview / Purpose:
This course is designed to help educators and administrators
understand and use the essential features and functions of Google Classroom effectively.
Participants will learn how to set up classes,
create course work,
use rubrics,
manage members,
provide feedback,
and communicate efficiently through the platform.

Learning Objectives:
- Create and manage Google Classroom classes.
- Create and organize course work and assignments.
- Develop and apply rubrics for grading.
- Invite and manage students, co-teachers, and guardians.
- Provide effective feedback and return graded work.
- Post announcements and manage classroom settings.
- Understand both the teacher and student user flows.

Weekly Course Plan / Schedule:
1. Introduction to Google Classroom
2. Creating a Class
3. Creating Course Work
4. Creating Rubrics
5. Inviting Members
6. Providing Feedback
7. Grading and Returning Work
8. Posting Announcements
9. Classroom Settings
10. Teacher and Student Flow
11. Working with Guardians
12. Final Review and Best Practices

References:
- Google Classroom Help Center
- Google for Education Training Center

Out-of-Class Learning:
Participants are expected to explore Google Classroom hands-on,
complete practice assignments,
and review help resources.
Estimated time: 1–2 hours per week.

Evaluation / Grading Criteria:
- Completion of practice tasks: 40%
- Participation in discussions (if applicable): 20%
- Final project (create and submit a sample class): 40%

Prerequisites / Requirements:
- Basic computer literacy
- A Google account
`;

const material = {
title: title,
description: description,
state: 'DRAFT'
};

try {
const createdMaterial = Classroom.Courses.CourseWorkMaterials.create(material, courseId);
Logger.log(`資料作成成功: ID = ${createdMaterial.id}, タイトル: ${createdMaterial.title}`);
} catch (e) {
Logger.log('資料作成失敗: ' + e.message);
}
}


実行後に以下のような資料が下書きで作成されました






Tips

API経由ではdescription(詳細)のテキストはstring型のため
太字、斜体、箇条書きなどのリッチテキスト形式は指定できないようです(2025/05/02現在)。

Google ClassroomのAPIで添付ファイル付きの課題を作成したい


Classroom の課題には以下のようなファイルを添付することができます
  • ドライブ
  • YouTube
  • 作成
  • アップロード
  • リンク


作成できるファイル
  • ドキュメント
  • スライド
  • スプレッドシート
  • 図形描画
  • フォーム


今回はGoogleドライブのファイルとYouTubeとWebページのリンクを添付するコードを試してみました




下記 Code.gs の courseId, driveFileId, youtubeId, linkUrl を自身の環境に合わせて書き換えて

createAssignmentWithAllAttachments() を実行すると

courseId で指定したクラスに課題の下書きが作成されます


Code.gs
function createAssignmentWithAllAttachments() {
const courseId = '776967326029'; // ここにクラスIDを入力
const driveFileId = '12345676890abcdefghijklmn'; // Google ドライブのファイルID
const youtubeId = 'XMCZE8tYAVU'; // YouTubeのビデオID(URLではない)
const linkUrl = 'https://edu.google.com/intl/en_ALL/workspace-for-education/products/classroom/'; // 添付するウェブリンク

const materials = [
{
driveFile: {
driveFile: {
id: driveFileId,
alternateLink: `https://drive.google.com/file/d/${driveFileId}/view`
},
shareMode: 'STUDENT_COPY'// VIEW, EDIT, STUDENT_COPY
}
},
{
link: {
url: linkUrl
}
},
{
youtubeVideo: {
id: youtubeId
}
}
];

const courseWork = {
title: 'Create a course in Google Classroom',
description: 'Discover how to design your course with essential elements.',
materials: materials,
workType: 'ASSIGNMENT',
state: 'DRAFT'
};

try {
const created = Classroom.Courses.CourseWork.create(courseWork, courseId);
Logger.log(`課題作成成功: ID = ${created.id}`);
} catch (e) {
Logger.log('課題作成失敗: ' + e.message);
}
}


実行後に作成される課題の下書きに添付ファイルが追加される



Tips 1

すでに作成されている課題への添付ファイル追加は API でサポートされていないようです

これかな



Tips 2

上記の Code.gs の shareMode: 'STUDENT_COPY' では「各生徒にコピーを作成」になります


画面上での選択肢は
  • 生徒がファイルを閲覧できる: VIEW
  • 生徒がファイルを編集できる: EDIT
  • 各生徒にコピーを作成: STUDENT_COPY






生徒の画面ではコピーされたドキュメントが割り当てられます



Reference

Method: courses.courseWork.create

REST Resource: courses.courseWorkMaterials 


ShareMode

AssigneeMode 

Method: courses.courseWork.patch


関連記事


2025年5月1日木曜日

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


自分が指導・参加しているクラスの名称とIDを取得するコードを試しました


下記 Code.gs では pageSize で 100 を設定していますが

必ず 100件 返ってくるとは限らないらしいです

ここでは nextPageToken がある限り繰り返しているので

すべてのクラスが取得できるはずです




Code.gs
function listAllCourses() {
let pageToken = null;
do {
const response = Classroom.Courses.list({
pageSize: 100,
pageToken: pageToken
});
(response.courses || []).forEach(course =>
Logger.log(`名称: ${course.name} (ID: ${course.id})`)
);
pageToken = response.nextPageToken;
} while (pageToken);
}



Tips 1

クラスの状態も取得したい場合
function listAllCoursesWithState() {
let pageToken = null;
do {
const response = Classroom.Courses.list({
pageSize: 100,
pageToken: pageToken
});
(response.courses || []).forEach(course =>
Logger.log(`名称: ${course.name} (ID: ${course.id}), 状態: ${course.courseState}`)
);
pageToken = response.nextPageToken;
} while (pageToken);
}


クラスの状態の種類
  • COURSE_STATE_UNSPECIFIED
  • ACTIVE
  • ARCHIVED
  • PROVISIONED
  • DECLINED
  • SUSPENDED



Tips 2

ACTIVE のクラスだけ取得したい場合
function listActiveCourses() {
let pageToken = null;
do {
const response = Classroom.Courses.list({
pageSize: 100,
pageToken: pageToken,
courseStates: ['ACTIVE'] // ← ACTIVE だけ指定
});
(response.courses || []).forEach(course =>
Logger.log(`名称: ${course.name} (ID: ${course.id}), 状態: ${course.courseState}`)
);
pageToken = response.nextPageToken;
} while (pageToken);
}



Reference

Method: courses.list 

CourseState

2025年4月30日水曜日

Google Classroom API で課題の割り当て先を指定したい


既存の課題を個別の生徒に割り当てるために必要な情報



下記 Code.gs の課題を個別の生徒に割り当てる場合

courseId, courseWorkId, studentIds の値を自身の環境に合わせて書き換えて

modifyCourseWorkAssignees() を実行すると

studentIds に設定した生徒にだけ課題が割り当てられます




Code.gs
function modifyCourseWorkAssigneesWithPaging() {
const courseId = '699141862609'; // 対象のクラスID
const courseWorkId = '767848967890'; // 対象の課題ID

// 1) まず全生徒の userId をページングで取得
const allIds = [];
let pageToken = null;
do {
const res = Classroom.Courses.Students.list(courseId, {
pageSize: 100, // 一度に取得する最大件数(最大 1000 まで指定可)
pageToken: pageToken
});
(res.students || []).forEach(s => allIds.push(s.userId));
pageToken = res.nextPageToken;
} while (pageToken);

// 2) ここで「割り当てたい生徒」の userId を列挙
const assignStudentIds = [
'12345678901234567890',
'09876543210987654321'
];

// 3) それ以外の userId を削除リストに
const removeIds = allIds.filter(id => !assignStudentIds.includes(id));

// 4) modifyAssignees 用リクエスト
const req = {
assigneeMode: 'INDIVIDUAL_STUDENTS',
modifyIndividualStudentsOptions: {
addStudentIds: assignStudentIds,
removeStudentIds: removeIds
}
};

// 5) 実行
try {
const updated = Classroom.Courses.CourseWork.modifyAssignees(
req,
courseId,
courseWorkId
);
Logger.log('更新成功: assigneeMode=' + updated.assigneeMode);
} catch (e) {
Logger.log('更新失敗: ' + e.message);
}
}


成功すると実行ログに assigneeMode=INDIVIDUAL_STUDENTS と出力されます



Tips 1: 全員に割り当てたい


全員に割り当てたい場合は assigneeMode: 'ALL_STUDENTS' にします

function updateCourseWorkToAllStudents() {
const courseId = '699141862609';
const courseWorkId = '767848967890';

// 全員配布に切り替えるリクエストボディ
const req = {
assigneeMode: 'ALL_STUDENTS'
};

try {
const updated = Classroom.Courses.CourseWork.modifyAssignees(
req,
courseId,
courseWorkId
);
Logger.log('更新成功: assigneeMode=' + updated.assigneeMode);
} catch (e) {
Logger.log('更新失敗: ' + e.message);
}
}




Tips 2: 課題作成時に個別に割り当てたい


function createCourseWorkForIndividualStudents() {
const courseId = '699141862609';

const studentIds = [
'12345678901234567890',
'09876543210987654321'
];

const courseWork = {
title: '個別指定テスト課題',
description: '特定の生徒にだけ配布します。',
workType: 'ASSIGNMENT',
state: 'PUBLISHED',
maxPoints: 50,
assigneeMode: 'INDIVIDUAL_STUDENTS',
individualStudentsOptions: {
studentIds: studentIds
},
dueDate: { year: 2025, month: 6, day: 1 },
dueTime: { hours: 23, minutes: 59 }
};

const created = Classroom.Courses.CourseWork.create(courseWork, courseId);
Logger.log('作成成功: ID=' + created.id);
}



Tips 3: 課題作成時に全員に割り当てたい


function createCourseWorkForAllStudents() {
const courseId = '699141862609';

const courseWork = {
title: '全員配布テスト課題',
description: 'この課題はクラス全員に配布されます。',
workType: 'ASSIGNMENT',
state: 'PUBLISHED',
maxPoints: 100,
assigneeMode: 'ALL_STUDENTS',
dueDate: { year: 2025, month: 6, day: 1 },
dueTime: { hours: 23, minutes: 59 }
};

const created = Classroom.Courses.CourseWork.create(courseWork, courseId);
Logger.log('作成成功: 課題ID=' + created.id);
}


Reference

Method: courses.courseWork.modifyAssignees 


ModifyIndividualStudentsOptions


Google Classroom API でクラスの参加者の一覧(fullName, userId)を取得したい


指定したクラスに参加している生徒と教師の名前とIDの取得を試したコードです

デフォルトでは 30 人まで取得できるようです

Query parameters


それより多い場合は nextPageToken がある限り繰り返し取得する必要があります



nextPageTokenに対応したコード

courseId を自身の環境に合わせて書き換えて

listAllParticipantsPaged() を実行すると

courseId で指定したクラスに参加している生徒と教師の一覧を出力できます


Code.gs
function listAllParticipantsPaged() {
const courseId = '699141862609';// 対象のクラスのcourseId
const opts = { pageSize: 30 }; // デフォルトの 30 件ずつ取得する

// 生徒
let token = null;
do {
const res = Classroom.Courses.Students.list(courseId, { ...opts, pageToken: token });
(res.students || []).forEach(s =>
Logger.log(`生徒: ${s.profile.name.fullName} ${s.userId}`)
);
token = res.nextPageToken;
} while (token);

// 先生
token = null;
do {
const res = Classroom.Courses.Teachers.list(courseId, { ...opts, pageToken: token });
(res.teachers || []).forEach(t =>
Logger.log(`先生: ${t.profile.name.fullName} ${t.userId}`)
);
token = res.nextPageToken;
} while (token);
}



Tips

生徒や教師の数がそれぞれ30人以下ならば以下のコードの方がシンプルに取得できる


Code.gs
function listAllParticipants() {
const courseId = '699141862609';
// Students
Classroom.Courses.Students.list(courseId).students?.forEach(s =>
Logger.log(`生徒: ${s.profile.name.fullName}, ID: ${s.userId}`)
);
// Teachers
Classroom.Courses.Teachers.list(courseId).teachers?.forEach(t =>
Logger.log(`先生: ${t.profile.name.fullName}, ID: ${t.userId}`)
);
}



Reference


Query parameters

Latest post

Google Formsでクイズを作りたい

Googleフォームには回答を判定するクイズモードがあります 今回はそのクイズモードで回答の判定とフィードバックについて書いていきます 「クイズモード」の表記: 日本語の表記は「テストにする」ですが 英語の表記は「Make this a quiz」となっています この記事ではそれ...