ניהול הזמנות לקורסים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
משאב Invitation
ב-Classroom מייצג הזמנה למשתמש להצטרף לקורס עם תפקיד ספציפי בקורס: תלמיד, מורה או בעלים.
כל משאב של Invitation
מכיל את השדות הבאים:
-
id
: מזהה שהוקצה על ידי Classroom להזמנה.
-
userId
: המזהה של המשתמש שהוזמן לקורס.
-
courseId
: הקורס שאליו המשתמש מוזמן.
-
role
: התפקיד בקורס שיוקצה למשתמש שהוזמן.
יצירת הזמנה
אפשר להשתמש בשיטה invitations.create()
כדי להזמין משתמש לקורס עם תפקיד ספציפי. כוללים את Invitation
resource בגוף הבקשה ומציינים את courseId
, userId
ו-role
.
אחזור הזמנה
כדי לאחזר הזמנה ספציפית, קוראים לשיטה invitations.get()
ומציינים את id
של ההזמנה.
אישור הזמנה
אישור ההזמנה מוחק אותה ומוסיף את המשתמש המוזמן לקורס עם התפקיד שצוין בהזמנה. כדי לאשר הזמנה, קוראים לשיטה invitations.accept()
ומציינים את id
של ההזמנה.
מחיקת הזמנה
הדרך היחידה לעדכן הזמנה היא למחוק אותה וליצור הזמנה חדשה. כדי למחוק את ההזמנה, צריך לבצע קריאה ל-method invitations.delete()
ולציין את id
.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. 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```"]]