Guardian
資源代表使用者 (例如家長),可接收學生的課程和課業資訊。監護人通常不是學生 Classroom 網域的成員,因此必須使用電子郵件地址邀請他們。
邀請函以 GuardianInvitation
資源表示。受邀的使用者會收到提示接受邀請的電子郵件。如果電子郵件地址未連結至 Google 帳戶,系統會提示使用者先建立帳戶,再接受邀請。
邀請使用者後,使用者接受邀請前,GuardianInvitation
的狀態為 PENDING
。使用者接受邀請後,GuardianInvitation
會標示為 COMPLETED
,並建立 Guardian
資源。
如果 GuardianInvitation
狀態過期,或授權使用者取消邀請 (例如使用 PatchGuardianInvitation
方法),狀態也可能會變更為 COMPLETED
。監護人、Classroom 老師或管理員也可以使用 Classroom 網頁應用程式或 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')))
回應會包含伺服器指派的 ID,可用於參照 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()