监护人资源代表用户(例如家长),可接收有关学生课程和作业的信息。监护人(通常不是学生的 Google 课堂网域的成员)必须使用其电子邮件地址受邀成为监护人。
此邀请会创建状态为 PENDING
的 GuardianInvitation 资源。然后,用户会收到一封提示其接受邀请的电子邮件。如果电子邮件地址未与 Google 帐号关联,系统会提示用户先创建一个,然后再接受邀请。
虽然邀请的状态为 PENDING
,但用户可以接受邀请,这会创建 Guardian 资源并将 GuardianInvitation 标记为 COMPLETED
。如果邀请过期或者授权用户取消了邀请(例如,使用 PatchGuardianInvitation
方法),该邀请也可能会变为 COMPLETED
。监护人、Google 课堂教师或管理员使用 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 课堂 API 执行的一些常见监护人操作。
创建监护人邀请
以下示例展示了如何使用 userProfiles.guardianInvitations.create()
方法创建监护人邀请:
Java
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。
取消监护人邀请
以下示例展示了如何使用 userProfiles.guardianInvitations.patch()
方法取消邀请:
Java
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()
列出特定学生的邀请
您可以使用 userProfiles.guardianInvitations.list()
方法获取针对特定学生发送的所有邀请的列表:
Java
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')))
默认情况下,系统仅会返回 PENDING
邀请。作为网域管理员,您也可以通过提供 state 参数来检索处于 COMPLETED
状态的邀请。
列出活跃的监护人
如果您想确定哪些用户是特定学生的活跃监护人,您可以使用 userProfiles.guardians.list()
方法。活跃的监护人是指已接受电子邮件邀请的监护人。
Java
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')))
移除监护人
您还可以使用 userProfiles.guardians.delete()
方法从学生中移除监护人:
Java
Python
service.userProfiles().guardians().delete(studentId='student@mydomain.edu',
guardianId='guardian@gmail.com').execute()