监护人资源表示接收学生课程和作业相关信息的用户(例如家长)。监护人(通常不是学生的 Google 课堂网域成员)必须使用电子邮件地址受邀,才能成为监护人。
此邀请会创建一个状态为 PENDING
的 GuardianInvitation 资源。然后,用户会收到一封提示其接受邀请的电子邮件。如果电子邮件地址未与 Google 帐号关联,系统会提示用户先创建一个,然后再接受邀请。
当邀请的状态为 PENDING
时,用户可以接受邀请,这会创建 Guardian 资源并将 GuardianInvitation 标记为 COMPLETED
的状态。如果邀请过期或者已获授权的用户取消了邀请(例如使用 PatchGuardianInvitation
方法),则该邀请也可能会变为 COMPLETED
。监护人、课堂教师或管理员还可以使用 Google 课堂界面或 DeleteGuardian
方法中断监护人关系。
谁可以管理监护人
下表介绍了根据当前经过身份验证的用户类型,您可以对监护人执行的操作:
瞄准镜
您可以通过以下三种范围管理监护人:
- 通过 https://www.googleapis.com/auth/classroom.guardianlinks.me.readonly,您可以查看用户自己的监护人。
- 通过 https://www.googleapis.com/auth/classroom.guardianlinks.students.readonly,您可以查看用户教授或管理的学生的 Guardians 和 GuardianInvitations。
- 通过 https://www.googleapis.com/auth/classroom.guardianlinks.students,您可以查看和修改用户教授或管理的学生的 Guardians 和 GuardianInvitations。
常用操作
本部分介绍了您可能想要使用 Google Classroom API 执行的一些常见监护人操作。
创建监护人邀请
以下示例展示了如何创建监护人邀请:
Python
guardianInvitation = {
'invitedEmailAddress': 'guardian@gmail.com',
}
guardianInvitation = service.userProfiles().guardianInvitations().create(
studentId='student@mydomain.edu',
body=guardianInvitation).execute()
print("Invitation created with id: {0}".format(guardianInvitation.get('invitationId')))
结果包含服务器分配的标识符,可用于引用 GuardianInvitation。
取消监护人邀请
下例显示了当用户不小心发出邀请时如何取消邀请:
Python
guardian_invite = {
'state': 'COMPLETE'
}
guardianInvitation = service.userProfiles().guardianInvitations().patch(
studentId='student@mydomain.edu',
invitationId=1234, # Replace with the invitation ID of the invitation you want to cancel
updateMask='state',
body=guardianInvitation).execute()
列出针对特定学生的邀请
您可以获取针对特定学生发送的所有邀请的列表:
Python
guardian_invites = []
page_token = None
while True:
response = service.userProfiles().guardianInvitations().list(
studentId='student@mydomain.edu').execute()
guardian_invites.extend(response.get('guardian_invites', []))
page_token = response.get('nextPageToken', None)
if not page_token:
break
if not courses:
print('No guardians invited for this {0}.'.format(response.get('studentId')))
else:
print('Guardian Invite:')
for guardian in guardian_invites:
print('An invite was sent to '.format(guardian.get('id'),
guardian.get('guardianId')))
默认情况下,系统只会返回“待处理”邀请。作为网域管理员,您也可以通过提供状态参数来检索处于“已完成”状态的邀请。
列出活跃的监护人
如果您想确定哪些用户是特定学生的有效监护人,则可以使用 ListGuardians 方法:
Python
guardian_invites = []
page_token = None
while True:
response = service.userProfiles().guardians().list(studentId='student@mydomain.edu').execute()
guardian_invites.extend(response.get('guardian_invites', []))
page_token = response.get('nextPageToken', None)
if not page_token:
break
if not courses:
print('No guardians invited for this {0}.'.format(response.get('studentId')))
else:
print('Guardian Invite:')
for guardian in guardian_invites:
print('An invite was sent to '.format(guardian.get('id'),
guardian.get('guardianId')))
移除监护人
您还可以使用 DeleteGuardian 方法从学生中移除监护人:
Python
service.userProfiles().guardians().delete(studentId='student@mydomain.edu',
guardianId='guardian@gmail.com').execute()