보호자 만들기 및 관리

Guardian 리소스는 학생의 과정 및 과정에 관한 정보를 받는 사용자(예: 학부모)를 나타냅니다. 일반적으로 학생의 클래스룸 도메인에 속하지 않는 보호자는 이메일 주소를 사용하여 초대해야 합니다.

초대는 GuardianInvitation 리소스로 표시됩니다. 초대를 받은 사용자는 수락을 요청하는 이메일을 받게 됩니다. 이메일 주소가 Google 계정과 연결되어 있지 않은 경우 사용자에게 초대를 수락하기 전에 계정을 만들라는 메시지가 표시됩니다.

사용자가 초대되고 초대를 수락하기 전에 GuardianInvitation의 상태는 PENDING입니다. 사용자가 초대를 수락하면 GuardianInvitationCOMPLETED로 표시되고 Guardian 리소스가 생성됩니다.

GuardianInvitation 상태는 만료되거나 승인된 사용자가 초대를 취소하면(예: PatchGuardianInvitation 메서드 사용) COMPLETED로 변경될 수도 있습니다. 보호자, 클래스룸 선생님 또는 관리자가 클래스룸 웹 애플리케이션 또는 DeleteGuardian 메서드를 사용하여 보호자 관계를 해제할 수도 있습니다.

보호자를 관리할 수 있는 사용자

다음 표에서는 인증된 사용자 유형에 따라 보호자와 관련하여 수행할 수 있는 작업을 설명합니다.

사용자 유형별 보호자 관련 ACL 표

범위

보호자를 관리할 수 있는 범위는 세 가지가 있습니다.

  • 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 클래스룸 API를 사용하여 실행할 수 있는 몇 가지 일반적인 보호자 작업을 설명합니다.

보호자 초대 만들기

다음 예는 userProfiles.guardianInvitations.create() 메서드를 사용하여 보호자 초대를 만드는 방법을 보여줍니다.

자바Python
classroom/snippets/src/main/java/CreateGuardianInvitation.java
GuardianInvitation guardianInvitation = null;

/* Create a GuardianInvitation object with state set to PENDING. See
https://developers.google.com/classroom/reference/rest/v1/userProfiles.guardianInvitations#guardianinvitationstate
for other possible states of guardian invitations. */
GuardianInvitation content =
    new GuardianInvitation()
        .setStudentId(studentId)
        .setInvitedEmailAddress(guardianEmail)
        .setState("PENDING");
try {
  guardianInvitation =
      service.userProfiles().guardianInvitations().create(studentId, content).execute();

  System.out.printf("Invitation created: %s\n", guardianInvitation.getInvitationId());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of studentId: %s", studentId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardianInvitation;
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로 수정합니다. 초대를 삭제하는 유일한 방법입니다.

자바Python
classroom/snippets/src/main/java/CancelGuardianInvitation.java
GuardianInvitation guardianInvitation = null;

try {
  /* Change the state of the GuardianInvitation from PENDING to COMPLETE. See
  https://developers.google.com/classroom/reference/rest/v1/userProfiles.guardianInvitations#guardianinvitationstate
  for other possible states of guardian invitations. */
  GuardianInvitation content =
      service.userProfiles().guardianInvitations().get(studentId, invitationId).execute();
  content.setState("COMPLETE");

  guardianInvitation =
      service
          .userProfiles()
          .guardianInvitations()
          .patch(studentId, invitationId, content)
          .set("updateMask", "state")
          .execute();

  System.out.printf(
      "Invitation (%s) state set to %s\n.",
      guardianInvitation.getInvitationId(), guardianInvitation.getState());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf(
        "There is no record of studentId (%s) or invitationId (%s).", studentId, invitationId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardianInvitation;
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 상태의 초대를 검색할 수도 있습니다.

자바Python
classroom/snippets/src/main/java/ListGuardianInvitationsByStudent.java
List<GuardianInvitation> guardianInvitations = new ArrayList<>();
String pageToken = null;

try {
  do {
    ListGuardianInvitationsResponse response =
        service
            .userProfiles()
            .guardianInvitations()
            .list(studentId)
            .setPageToken(pageToken)
            .execute();

    /* Ensure that the response is not null before retrieving data from it to avoid errors. */
    if (response.getGuardianInvitations() != null) {
      guardianInvitations.addAll(response.getGuardianInvitations());
      pageToken = response.getNextPageToken();
    }
  } while (pageToken != null);

  if (guardianInvitations.isEmpty()) {
    System.out.println("No guardian invitations found.");
  } else {
    for (GuardianInvitation invitation : guardianInvitations) {
      System.out.printf("Guardian invitation id: %s\n", invitation.getInvitationId());
    }
  }
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of studentId (%s).", studentId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardianInvitations;
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() 메서드를 사용하세요. 활성 보호자는 초대를 수락한 보호자입니다.

자바Python
classroom/snippets/src/main/java/ListGuardians.java
List<Guardian> guardians = new ArrayList<>();
String pageToken = null;

try {
  do {
    ListGuardiansResponse response =
        service.userProfiles().guardians().list(studentId).setPageToken(pageToken).execute();

    /* Ensure that the response is not null before retrieving data from it to avoid errors. */
    if (response.getGuardians() != null) {
      guardians.addAll(response.getGuardians());
      pageToken = response.getNextPageToken();
    }
  } while (pageToken != null);

  if (guardians.isEmpty()) {
    System.out.println("No guardians found.");
  } else {
    for (Guardian guardian : guardians) {
      System.out.printf(
          "Guardian name: %s, guardian id: %s, guardian email: %s\n",
          guardian.getGuardianProfile().getName().getFullName(),
          guardian.getGuardianId(),
          guardian.getInvitedEmailAddress());
    }
  }

} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of studentId (%s).", studentId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardians;
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() 메서드를 사용하여 학생에서 보호자를 삭제할 수도 있습니다.

자바Python
classroom/snippets/src/main/java/DeleteGuardian.java
try {
  service.userProfiles().guardians().delete(studentId, guardianId).execute();
  System.out.printf("The guardian with id %s was deleted.\n", guardianId);
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of guardianId (%s).", guardianId);
  }
}
service.userProfiles().guardians().delete(studentId='student@mydomain.edu',
                                        guardianId='guardian@gmail.com').execute()