Управление приглашениями на курсы
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Ресурс Invitation
в Classroom представляет собой приглашение пользователю присоединиться к курсу с определенной ролью курса : студент, преподаватель или владелец.
Каждый ресурс Invitation
содержит следующие поля:
-
id
: Идентификатор приглашения, присвоенный классом. -
userId
: идентификатор пользователя, приглашенного на курс. -
courseId
: курс, на который приглашается пользователь. -
role
: Роль курса , которую приглашенный пользователь будет иметь в курсе.
Создать приглашение
Метод invitations.create()
можно использовать для приглашения пользователя на курс с определённой ролью. Включите ресурс Invitation
в тело запроса и укажите courseId
, userId
и role
.
Получить приглашение
Получите конкретное приглашение, вызвав метод invitations.get()
и указав id
приглашения.
Принять приглашение
Принятие приглашения удаляет его и добавляет приглашенного пользователя в курс с указанной в приглашении ролью. Чтобы принять приглашение, вызовите метод invitations.accept()
и укажите id
приглашения.
Удалить приглашение
Единственный способ обновить приглашение — удалить его и создать новое. Чтобы удалить приглашение, вызовите метод invitations.delete()
и укажите его id
.
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-08-01 UTC.
[null,null,["Последнее обновление: 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```"]]