יצירה וניהול של קבוצות תלמידים

אתם יכולים להשתמש בקבוצות תלמידים כדי לארגן את התלמידים בקבוצות ספציפיות למטרות שונות, כמו מטלות ייעודיות ופעילויות משותפות. אפשר להשתמש ב-Classroom API כדי ליצור, לשנות ולקרוא קבוצות של תלמידים בקורס בשם האדמינים והמורים.

אפשר ליצור, לעדכן, למחוק ולקרוא קבוצות של תלמידים באמצעות השיטות הבאות:

אתם יכולים גם להוסיף חברים לקבוצת תלמידים, להסיר חברים ממנה ולקרוא את השמות שלהם בשיטות הבאות:

גישה לשיטות של קבוצות תלמידים בתוכנית ההפצה המקדימה למפתחים

כדי לגשת לשיטות של קבוצות סטודנטים בתצוגה מקדימה, צריך לבצע את הפעולות הבאות:

דרישות רישוי ודרישות סף

כדי ליצור, לשנות או למחוק קבוצות של תלמידים בקורס, ולהוסיף או להסיר חברים מקבוצות של תלמידים, צריך לעמוד בתנאים הבאים:

קריאת קבוצות תלמידים והחברים בהן

אדמינים ומורים בקורס יכולים לקרוא נתונים של קבוצות תלמידים, בלי קשר לסוג הרישיון שהוקצה להם. כלומר, בקשות לנקודות הקצה 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.

אם השתמשתם במדריך למתחילים של Python כנקודת התחלה, צריך לשנות את שירות Classroom כדי לגשת לשיטות של גרסת טרום-השקה.

Python

classroom_service = 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') 

בדיקת הזכאות של המשתמשים

ממשק Classroom API מספק את נקודת הקצה userProfiles.checkUserCapability כדי לעזור לכם לקבוע באופן יזום אם משתמש יכול ליצור ולשנות קבוצות של תלמידים ואת החברים בהן.

נקודת הקצה userProfiles.checkUserCapability בודקת רק אם משתמש עומד בדרישות לשימוש ביכולת מסוימת, כמו שינוי קבוצות של תלמידים. אין בו מידע על התפקיד בקורס. לדוגמה, גם אם למשתמש יש את היכולת CREATE_STUDENT_GROUP, אם הוא תלמיד בקורס, בקשה לנקודת הקצה CreateStudentGroup לא תצליח.

Python

def check_student_groups_update_capability(classroom_service, course_id):     """Checks whether a user is able to create and modify student groups in a course."""     capability = classroom_service.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 allowed to create and modify student groups.")     else:         print("User is not allowed 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,         previewVersion="V1_20250630_PREVIEW",     ).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",         previewVersion="V1_20250630_PREVIEW"     ).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,         previewVersion="V1_20250630_PREVIEW",     ).execute()      print(response) 

אפשר לאחזר את קבוצות התלמידים בקורס באמצעות נקודת הקצה (endpoint) ListStudentGroups:

Python

def list_student_groups(classroom_service, course_id):     results = classroom_service.courses().studentGroups().list(         courseId=course_id,         previewVersion="V1_20250630_PREVIEW"     ).execute()      studentGroups = results.get("studentGroups") 

ניהול של חברי קבוצת תלמידים

אחרי שיוצרים את קבוצת התלמידים, אפשר להוסיף לה חברים.

Python

def add_student_group_member(classroom_service, course_id, student_group_id):     body = {         "userId": "[email protected]"     }      response = classroom_service.courses().studentGroups().studentGroupMembers().create(         courseId=course_id,         studentGroupId=student_group_id,         body=body,         previewVersion="V1_20250630_PREVIEW"     ).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="[email protected]",         previewVersion="V1_20250630_PREVIEW"     ).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,         previewVersion="V1_20250630_PREVIEW"     ).execute()      print(results.get("studentGroupMembers")) 

כל משאב StudentGroupMember כולל את courseId, studentGroupId ו-userId של חברי הקבוצה.