Dodatki do Google Classroom są teraz ogólnie dostępne dla programistów. Więcej informacji znajdziesz w
dokumentacji dodatków.
Zarządzanie zaproszeniami na zajęcia
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Invitation
Zasó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
.
Odzyskiwanie zaproszenia
Aby pobrać konkretne zaproszenie, wywołaj metodę invitations.get()
i określ id
zaproszenia.
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.
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
.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-01 UTC.
[null,null,["Ostatnia aktualizacja: 2025-08-01 UTC."],[],[],null,["# Manage Course Invitations\n\nAn [`Invitation` resource](/workspace/classroom/reference/rest/v1/invitations) in Classroom represents an invitation\nfor a user to join a course with a specific [course role](/workspace/classroom/reference/rest/v1/invitations#courserole): student, teacher,\nor owner.\n\nEach `Invitation` resource contains the following fields:\n\n- `id`: Classroom-assigned identifier for the invitation.\n- `userId`: The ID of the user that has been invited to the course.\n- `courseId`: The course that the user is being invited to.\n- `role`: The [course role](/workspace/classroom/reference/rest/v1/invitations#courserole) that the invited user will have in the course.\n\nCreate an Invitation\n--------------------\n\nThe [`invitations.create()`](/workspace/classroom/reference/rest/v1/invitations/create) method can be used to invite a user to a course\nwith a specific role. Include the [`Invitation` resource](/workspace/classroom/reference/rest/v1/invitations) in the request body\nand specify the `courseId`, `userId`, and `role`. \n\n### Java\n\nclassroom/snippets/src/main/java/CreateInvitation.java \n[View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/classroom/snippets/src/main/java/CreateInvitation.java) \n\n```java\nInvitation invitation = null;\ntry {\n /* Set the role the user is invited to have in the course. Possible values of CourseRole can be\n found here: https://developers.google.com/classroom/reference/rest/v1/invitations#courserole.*/\n Invitation content =\n new Invitation().setCourseId(courseId).setUserId(userId).setRole(\"TEACHER\");\n\n invitation = service.invitations().create(content).execute();\n\n System.out.printf(\n \"User (%s) has been invited to course (%s).\\n\",\n invitation.getUserId(), invitation.getCourseId());\n} catch (GoogleJsonResponseException e) {\n // TODO (developer) - handle error appropriately\n GoogleJsonError error = e.getDetails();\n if (error.getCode() == 404) {\n System.out.printf(\"The course or user does not exist.\\n\");\n }\n throw e;\n} catch (Exception e) {\n throw e;\n}\nreturn invitation;\n```\n\nRetrieve an Invitation\n----------------------\n\nRetrieve a specific invitation by calling the [`invitations.get()`](/workspace/classroom/reference/rest/v1/invitations/get) method\nand specifying the `id` of the invitation. \n\n### Java\n\nclassroom/snippets/src/main/java/GetInvitation.java \n[View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/classroom/snippets/src/main/java/GetInvitation.java) \n\n```java\nInvitation invitation = null;\ntry {\n invitation = service.invitations().get(id).execute();\n System.out.printf(\n \"Invitation (%s) for user (%s) in course (%s) retrieved.\\n\",\n invitation.getId(), invitation.getUserId(), invitation.getCourseId());\n} catch (GoogleJsonResponseException e) {\n GoogleJsonError error = e.getDetails();\n if (error.getCode() == 404) {\n System.out.printf(\"The invitation id (%s) does not exist.\\n\", id);\n }\n throw e;\n} catch (Exception e) {\n throw e;\n}\nreturn invitation;\n```\n\nAccept an Invitation\n--------------------\n\nAccepting an invitation deletes the invitation and adds the invited\nuser to the course with the role specified in the invitation. Accept an\ninvitation by calling the [`invitations.accept()`](/workspace/classroom/reference/rest/v1/invitations/accept) method and specifying the\n`id` of the invitation. \n\n### Java\n\nclassroom/snippets/src/main/java/AcceptInvitation.java \n[View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/classroom/snippets/src/main/java/AcceptInvitation.java) \n\n```java\ntry {\n service.invitations().accept(id).execute();\n System.out.printf(\"Invitation (%s) was accepted.\\n\", id);\n} catch (GoogleJsonResponseException e) {\n GoogleJsonError error = e.getDetails();\n if (error.getCode() == 404) {\n System.out.printf(\"The invitation id (%s) does not exist.\\n\", id);\n }\n throw e;\n} catch (Exception e) {\n throw e;\n}\n```\n\nDelete an Invitation\n--------------------\n\nThe only way to update an invitation is to delete it and create a new\ninvitation. To delete the invitation, call the [`invitations.delete()`](/workspace/classroom/reference/rest/v1/invitations/delete) method\nand specify the `id`. \n\n### Java\n\nclassroom/snippets/src/main/java/DeleteInvitation.java \n[View on GitHub](https://github.com/googleworkspace/java-samples/blob/main/classroom/snippets/src/main/java/DeleteInvitation.java) \n\n```java\ntry {\n service.invitations().delete(id).execute();\n System.out.printf(\"Invitation (%s) was deleted.\\n\", id);\n} catch (GoogleJsonResponseException e) {\n GoogleJsonError error = e.getDetails();\n if (error.getCode() == 404) {\n System.out.printf(\"The invitation id (%s) does not exist.\\n\", id);\n }\n throw e;\n} catch (Exception e) {\n throw e;\n}\n```"]]