אתם יכולים להשתמש בקבוצות תלמידים כדי לארגן את התלמידים בקבוצות ספציפיות למטרות שונות, כמו מטלות ייעודיות ופעילויות משותפות. אפשר להשתמש ב-Classroom API כדי ליצור, לשנות ולקרוא קבוצות של תלמידים בקורס בשם האדמינים והמורים.
אפשר ליצור, לעדכן, למחוק ולקרוא קבוצות של תלמידים באמצעות השיטות הבאות:
אתם יכולים גם להוסיף חברים לקבוצת תלמידים, להסיר חברים ממנה ולקרוא את הפרטים שלהם באמצעות השיטות הבאות:
דרישות רישוי ודרישות סף
כדי ליצור, לשנות או למחוק קבוצות תלמידים בקורס, ולהוסיף או להסיר חברים מקבוצות תלמידים, צריך לעמוד בתנאים הבאים:
- המשתמש ששולח את הבקשה חייב להיות מורה בקורס או אדמין בדומיין.
- למשתמש ששולח את הבקשה צריך להיות מוקצה רישיון ל-Google Workspace for Education Plus.
- לבעלי הקורס צריך להיות רישיון ל-Google Workspace for Education Plus.
קריאת קבוצות תלמידים והחברים בהן
אדמינים ומורים בקורס יכולים לקרוא נתונים של קבוצות תלמידים, בלי קשר לסוג הרישיון שהוקצה להם. כלומר, בקשות לנקודות הקצה ListStudentGroups ו-ListStudentGroupMembers מותרות בשם כל אדמין או מורה בקורס.
דרישות מוקדמות לקוד לדוגמה
במדריך הזה יש דוגמאות קוד ב-Python, ואנחנו יוצאים מנקודת הנחה שיש לכם את הדברים הבאים:
- פרויקט ב-Google Cloud. אפשר להגדיר אחד לפי ההוראות שבמדריך לתחילת העבודה עם Python.
- הוספנו את היקפי ההרשאות הבאים למסך ההסכמה ל-OAuth של הפרויקט שלך:
https://www.googleapis.com/auth/classroom.rosters-
https://www.googleapis.com/auth/classroom.rosters.readonlyלנקודות קצה לקריאה בלבד.
- מזהה של קורס שבו רוצים לנהל קבוצות תלמידים. לבעלי הקורס צריך להיות רישיון ל-Google Workspace for Education Plus.
- גישה לפרטי הכניסה של מורה או אדמין עם רישיון ל-Google Workspace for Education Plus.
בדיקת הזכאות של המשתמשים
ממשק Classroom API מספק את נקודת הקצה userProfiles.checkUserCapability כדי לעזור לכם לקבוע באופן יזום אם משתמש יכול ליצור ולשנות קבוצות תלמידים ואת החברים בהן. השיטה זמינה דרך תוכנית ההפצה המקדימה למפתחים. אם השתמשתם בהתחלה המהירה של Python כנקודת התחלה, צריך להגדיר שירות Classroom חדש שיכול לגשת לשיטות בתצוגה מקדימה:
Python
classroom_service_with_capability_endpoint = googleapiclient.discovery.build(
serviceName='classroom',
version='v1',
credentials=creds,
static_discovery=False,
discoveryServiceUrl='https://classroom.googleapis.com/$discovery/rest?labels=DEVELOPER_PREVIEW&key=API_KEY')
נקודת הקצה userProfiles.checkUserCapability בודקת רק אם משתמש עומד בדרישות לשימוש ביכולת מסוימת, כמו שינוי קבוצות של תלמידים. אין בו מידע על התפקיד בקורס. לדוגמה, גם אם למשתמש יש את היכולת CREATE_STUDENT_GROUP, אם הוא תלמיד בקורס, בקשה לנקודת הקצה CreateStudentGroup לא תצליח.
Python
def check_student_groups_update_capability():
"""Checks whether a user is eligible to create and modify student groups."""
capability = classroom_service_with_capability_endpoint.userProfiles().checkUserCapability(
userId="me", # Can also be set to a different user's email address or ID
capability="CREATE_STUDENT_GROUP",
previewVersion="V1_20240930_PREVIEW" # Required while the method is in the DPP.
).execute()
if capability.get("allowed"): # Retrieve the `allowed` boolean from the response.
print("User is eligible to create and modify student groups.")
else:
print("User is not eligible to create and modify student groups.")
ניהול של קבוצות תלמידים
אפשר ליצור קבוצות של תלמידים באמצעות נקודת הקצה CreateStudentGroup.
Python
def create_student_group(classroom_service, course_id):
body = {
"title": "Team Blue"
}
response = classroom_service.courses().studentGroups().create(
courseId=course_id,
body=body
).execute()
print(response)
התשובה מכילה את id של קבוצת התלמידים החדשה שנוצרה, את courseId ואת title של קבוצת התלמידים.
אפשר להשתמש בקבוצת התלמידים id כדי לעדכן או למחוק את קבוצת התלמידים הספציפית.
Python
def update_student_group(classroom_service, course_id, student_group_id):
body = {
"title": "Team Green"
}
response = classroom_service.courses().studentGroups().patch(
courseId=course_id,
id=student_group_id,
body=body,
updateMask="title"
).execute()
print(response)
def delete_student_group(classroom_service, course_id, student_group_id):
response = classroom_service.courses().studentGroups().delete(
courseId=course_id,
id=student_group_id
).execute()
print(response)
אפשר לאחזר את קבוצות התלמידים בקורס באמצעות נקודת הקצה (endpoint) ListStudentGroups:
Python
def list_student_groups(classroom_service, course_id):
results = classroom_service.courses().studentGroups().list(
courseId=course_id
).execute()
studentGroups = results.get("studentGroups")
ניהול של חברי קבוצת תלמידים
אחרי שיוצרים את קבוצת התלמידים, אפשר להוסיף לה חברים.
Python
def add_student_group_member(classroom_service, course_id, student_group_id):
body = {
"userId": "student@schooldomain.com"
}
response = classroom_service.courses().studentGroups().studentGroupMembers().create(
courseId=course_id,
studentGroupId=student_group_id,
body=body
).execute()
print(response)
אם רוצים להסיר חבר מקבוצת תלמידים, שולחים בקשה כמו הבקשה הבאה:
Python
def delete_student_group_member(classroom_service, course_id, student_group_id):
response = classroom_service.courses().studentGroups().studentGroupMembers().delete(
courseId=course_id,
studentGroupId=student_group_id,
userId="student@schooldomain.com"
).execute()
print(response)
כדי לקרוא את החברים בקבוצה, שולחים את הבקשה הבאה:
Python
def list_student_group_members(classroom_service, course_id, student_group_id):
results = classroom_service.courses().studentGroups().studentGroupMembers().list(
courseId=course_id,
studentGroupId=student_group_id
).execute()
print(results.get("studentGroupMembers"))
כל משאב StudentGroupMember כולל את courseId, את studentGroupId ואת userId של חבר הקבוצה.