Guardian
资源表示接收学生课程和作业相关信息的家长等用户。监护人(通常不是学生 Google 课堂网域的成员)必须通过其电子邮件地址受邀加入。
邀请由 GuardianInvitation
资源表示。受邀用户会收到一封提示其接受邀请的电子邮件。如果该电子邮件地址未与 Google 账号相关联,系统会提示用户先创建一个 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()
方法创建监护人邀请:
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()
方法将邀请的状态从 PENDING
修改为 COMPLETE
。这是移除邀请的唯一方法。
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()
方法获取已针对特定学生发送的所有邀请的列表。默认情况下,系统只会返回 PENDING
邀请。网域管理员还可以通过提供 states
参数来检索处于 COMPLETED
状态的邀请。
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')))
列出有效的监护人
如需确定哪些用户是特定学生的有效监护人,请使用 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()