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;
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;
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;}
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;}
[[["容易理解","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"]],["上次更新時間:2024-11-18 (世界標準時間)。"],[[["An Invitation resource in Classroom allows users to join a course with a specific role, containing fields like `id`, `userId`, `courseId`, and `role`."],["You can create, retrieve, accept, and delete invitations using the Classroom API's `invitations` methods, specifying necessary parameters like `courseId`, `userId`, `role`, and `id`."],["Accepting an invitation adds the user to the course with the specified role and deletes the invitation, while deleting an invitation requires using the `invitations.delete()` method."],["Updating an invitation involves deleting the existing one and creating a new one with the desired changes."]]],[]]