כדי שמשתמש יוכל להצטרף לקורס עם התפקיד שצוין, יוצרים הזמנה ל-method invitations.create(). עליכם לכלול את משאב ההזמנה בגוף הבקשה ולציין את הערכים courseId, userId ו-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;
אחזור הזמנה
כדי לאחזר הזמנה ספציפית, מתקשרים ל-method invitations.get() ומציינים את id של ההזמנה.
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;
אישור הזמנה
אישור ההזמנה לקורס גורם למחיקה של ההזמנה ולהוספה לקורס עם התפקיד שצוין בהזמנה. כדי לאשר את ההזמנה, מתקשרים ל-method invitations.accept() ומציינים את id של ההזמנה.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"חסרים לי מידע או פרטים"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"התוכן מורכב מדי או עם יותר מדי שלבים"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"התוכן לא עדכני"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"בעיה בתרגום"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"בעיה בדוגמאות/בקוד"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"סיבה אחרת"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"התוכן קל להבנה"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"התוכן עזר לי לפתור בעיה"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"סיבה אחרת"
}]
{"lastModified": "\u05e2\u05d3\u05db\u05d5\u05df \u05d0\u05d7\u05e8\u05d5\u05df: 2023-09-14 (\u05e9\u05e2\u05d5\u05df UTC)."}
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2023-09-14 (שעון UTC)."]]