Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Zaproszenie w Classroom to zaproszenie użytkownika na zajęcia z określoną rolą.
Każdy zasób zaproszenia zawiera następujące pola:
id zaproszenia przypisanego przez Classroom.
userId użytkownika, do którego zostało wysłane zaproszenie.
courseId zajęć, na które jest zapraszany użytkownik.
rolerolę, jaką zaproszony użytkownik będzie miał na zajęciach.
Utwórz zaproszenie
Utwórz zaproszenie, aby użytkownik mógł dołączyć do zajęć o określonej roli, wywołując metodę invitations.create(). Dołącz zasób zaproszenia w treści żądania i określ courseId, userId oraz role.
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;
Pobierz zaproszenie
Pobierz konkretne zaproszenie, wywołując metodę invitations.get() i określając id zaproszenia.
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;
Zaakceptuj zaproszenie
Zaakceptowanie zaproszenia na zajęcia spowoduje usunięcie tego zaproszenia i dodanie użytkownika do tych zajęć z przypisaną rolą określoną w zaproszeniu. Aby zaakceptować zaproszenie, wywołaj metodę invitations.accept() i określ id zaproszenia.
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;
}
Usuwanie zaproszenia
Jedynym sposobem zaktualizowania zaproszenia jest usunięcie go i utworzenie nowego. Aby usunąć zaproszenie, wywołaj metodę invitations.delete() i określ id.