Guardian
资源代表接收学生课程和课业信息的用户(例如家长)。监护人通常不是学生的 Google 课堂网域成员,因此必须使用其电子邮件地址进行邀请。
邀请由 GuardianInvitation
资源表示。受邀用户会收到一封提示其接受邀请的电子邮件。如果电子邮件地址未与 Google 账号相关联,系统会提示用户在接受邀请之前创建一个。
在用户收到邀请但尚未接受邀请时,GuardianInvitation
的状态为 PENDING
。用户接受邀请后,GuardianInvitation
会被标记为 COMPLETED
,并且系统会创建 Guardian
资源。
如果 GuardianInvitation
状态过期或已获授权的用户取消邀请(例如,使用 PatchGuardianInvitation
方法),该状态也可能会更改为 COMPLETED
。家长、Google 课堂教师或管理员也可以使用 Google 课堂 Web 应用或 DeleteGuardian
方法解除家长关系。
谁可以管理监护人
下表介绍了可针对家长执行的操作(具体取决于经过身份验证的用户类型):
范围
您可以通过以下三种范围管理家长:
https://www.googleapis.com/auth/classroom.guardianlinks.me.readonly
:查看用户自己的监护人。https://www.googleapis.com/auth/classroom.guardianlinks.students.readonly
:查看用户教授或管理的学生的监护人和监护人邀请。https://www.googleapis.com/auth/classroom.guardianlinks.students
:查看和管理用户所教授或管理的学生的监护人和监护人邀请。
常用操作
本部分介绍了您可能希望使用 Google Classroom API 执行的一些常见家长操作。
创建家长邀请
以下示例展示了如何使用 userProfiles.guardianInvitations.create()
方法创建监护人邀请:
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
。
取消家长邀请
如需取消邀请,请调用 userProfiles.guardianInvitations.patch()
方法,将邀请的状态从 PENDING
修改为 COMPLETE
。这是移除邀请的唯一方式。
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()
列出特定学生的邀请
您可以使用 userProfiles.guardianInvitations.list()
方法获取已向特定学生发送的所有邀请的列表。默认情况下,系统只会返回 PENDING
邀请。网域管理员还可以通过提供 states
参数来检索处于 COMPLETED
状态的邀请。
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')))
列出活跃的监护人
如需确定哪些用户是特定学生的有效监护人,请使用 userProfiles.guardians.list()
方法。“有效的监护人”是指已接受邀请的监护人。
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')))
移除监护人
您还可以使用 userProfiles.guardians.delete()
方法为学生移除监护人:
service.userProfiles().guardians().delete(studentId='student@mydomain.edu',
guardianId='guardian@gmail.com').execute()