강의 초대 관리

클래스룸의 Invitation 리소스는 사용자가 학생, 교사 또는 소유자와 같은 특정 수업 역할로 수업에 참여하도록 하는 초대장을 나타냅니다.

Invitation 리소스에는 다음 필드가 포함됩니다.

  • id: 초대에 대해 Classroom에서 할당한 식별자입니다.
  • userId: 수업에 초대된 사용자의 ID입니다.
  • courseId: 사용자가 초대된 강의입니다.
  • role: 초대된 사용자가 과정에서 갖게 될 과정 역할입니다.

초대 만들기

invitations.create() 메서드를 사용하여 특정 역할로 사용자를 수업에 초대할 수 있습니다. 요청 본문에 Invitation 리소스를 포함하고 courseId, userId, role를 지정합니다.

자바

classroom/snippets/src/main/java/CreateInvitation.java
Invitation invitation = null;
try {
  /* Set the role the user is invited to have in the course. Possible values of CourseRole can be
  found here: https://developers.google.com/classroom/reference/rest/v1/invitations#courserole.*/
  Invitation content =
      new Invitation().setCourseId(courseId).setUserId(userId).setRole("TEACHER");

  invitation = service.invitations().create(content).execute();

  System.out.printf(
      "User (%s) has been invited to course (%s).\n",
      invitation.getUserId(), invitation.getCourseId());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The course or user does not exist.\n");
  }
  throw e;
} catch (Exception e) {
  throw e;
}
return invitation;

초대 가져오기

invitations.get() 메서드를 호출하고 초대의 id를 지정하여 특정 초대를 가져옵니다.

자바

classroom/snippets/src/main/java/GetInvitation.java
Invitation invitation = null;
try {
  invitation = service.invitations().get(id).execute();
  System.out.printf(
      "Invitation (%s) for user (%s) in course (%s) retrieved.\n",
      invitation.getId(), invitation.getUserId(), invitation.getCourseId());
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The invitation id (%s) does not exist.\n", id);
  }
  throw e;
} catch (Exception e) {
  throw e;
}
return invitation;

초대 수락하기

초대를 수락하면 초대가 삭제되고 초대된 사용자가 초대에 지정된 역할로 강의에 추가됩니다. invitations.accept() 메서드를 호출하고 초대 id을 지정하여 초대를 수락합니다.

자바

classroom/snippets/src/main/java/AcceptInvitation.java
try {
  service.invitations().accept(id).execute();
  System.out.printf("Invitation (%s) was accepted.\n", id);
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The invitation id (%s) does not exist.\n", id);
  }
  throw e;
} catch (Exception e) {
  throw e;
}

초대 삭제

초대장을 업데이트하는 유일한 방법은 초대장을 삭제하고 새 초대장을 만드는 것입니다. 초대장을 삭제하려면 invitations.delete() 메서드를 호출하고 id을 지정합니다.

자바

classroom/snippets/src/main/java/DeleteInvitation.java
try {
  service.invitations().delete(id).execute();
  System.out.printf("Invitation (%s) was deleted.\n", id);
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The invitation id (%s) does not exist.\n", id);
  }
  throw e;
} catch (Exception e) {
  throw e;
}