保護者リソースは、生徒のコースと課題に関する情報を受け取る親などのユーザーを表します。保護者(通常、生徒の Classroom ドメインのメンバーではない)は、保護者のメールアドレスを使用して招待してもらう必要があります。
この招待により、状態が PENDING
の GuardianInvitation リソースが作成されます。ユーザーは、招待の承諾を求めるメールを受信します。メールアドレスが Google アカウントに関連付けられていない場合、ユーザーは招待を受諾する前にメールアドレスの作成を求められます。
招待のステータスが PENDING
の場合、ユーザーは招待を受け入れて、Guardian リソースを作成し、GuardianInvitation に COMPLETED
ステータスのマークを付けることができます。招待状の期限が切れた場合、または承認されたユーザーが(PatchGuardianInvitation
メソッドなどを使用して)招待をキャンセルした場合にも、招待が COMPLETED
になります。Classroom のユーザー インターフェースまたは DeleteGuardian
メソッドを使用して、保護者、Classroom の教師、または管理者によって管理者との関係が解除される場合もあります。
保護者を管理できる人
次の表は、現在認証されているユーザーのタイプに応じて、保護者に対して実行できるアクションを示しています。
スコープ
保護者は 3 つの範囲で管理できます。
- 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 を使用すると、ユーザーが指導または管理している生徒の 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')))
デフォルトでは、「PENDING」の招待のみが返されます。ドメイン管理者は、状態パラメータを指定して COMPLETED 状態の招待を取得することもできます。
アクティブな保護者の一覧を取得する
特定の生徒のアクティブな保護者として誰かを確認するには、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()