Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
InvitationZasób w Classroom to zaproszenie użytkownika do dołączenia do zajęć z określoną rolą na zajęciach: uczeń, nauczyciel lub właściciel.
Każdy zasób Invitation zawiera te pola:
id: identyfikator zaproszenia przypisany przez Classroom.
userId: identyfikator użytkownika, który został zaproszony na zajęcia.
courseId: kurs, na który zapraszany jest użytkownik.
role: rola w kursie, jaką zaproszony użytkownik będzie mieć w kursie.
Tworzenie zaproszenia
Metody invitations.create() można użyć, aby zaprosić użytkownika do udziału w kursie z określoną rolą. W treści żądania umieść Invitation zasób i określ courseId, userId i role.
Invitationinvitation=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.*/Invitationcontent=newInvitation().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(GoogleJsonResponseExceptione){// TODO (developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The course or user does not exist.\n");}throwe;}catch(Exceptione){throwe;}returninvitation;
Odzyskiwanie zaproszenia
Aby pobrać konkretne zaproszenie, wywołaj metodę invitations.get() i określ id zaproszenia.
Invitationinvitation=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(GoogleJsonResponseExceptione){GoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The invitation id (%s) does not exist.\n",id);}throwe;}catch(Exceptione){throwe;}returninvitation;
Akceptowanie zaproszenia
Zaakceptowanie zaproszenia powoduje jego usunięcie i dodanie zaproszonego użytkownika do zajęć z rolą określoną w zaproszeniu. Zaakceptuj zaproszenie, wywołując metodę invitations.accept() i określając id zaproszenia.
try{service.invitations().accept(id).execute();System.out.printf("Invitation (%s) was accepted.\n",id);}catch(GoogleJsonResponseExceptione){GoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The invitation id (%s) does not exist.\n",id);}throwe;}catch(Exceptione){throwe;}
Usuwanie zaproszenia
Jedynym sposobem na zaktualizowanie zaproszenia jest jego usunięcie i utworzenie nowego. Aby usunąć zaproszenie, wywołaj metodę invitations.delete() i określ id.
try{service.invitations().delete(id).execute();System.out.printf("Invitation (%s) was deleted.\n",id);}catch(GoogleJsonResponseExceptione){GoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The invitation id (%s) does not exist.\n",id);}throwe;}catch(Exceptione){throwe;}
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 2025-08-01 UTC."],[],[],null,[]]