학생 그룹을 사용하면 학생들을 타겟팅된 과제, 공동작업 활동 등 수업 환경을 개선하기 위한 그룹으로 나눌 수 있습니다. 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
- 학생 그룹을 관리해야 하는 수업의 ID입니다. 과정 소유자에게 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)
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가 포함됩니다.