Hiện tại, các nhà phát triển đã có thể sử dụng rộng rãi tiện ích bổ sung của Google Lớp học! Vui lòng xem tài liệu về tiện ích bổ sung để biết thêm thông tin.
Tạo lời mời để người dùng có thể tham gia khoá học với vai trò đã chỉ định bằng cách gọi phương thức invitations.create(). Đưa Tài nguyên lời mời vào nội dung yêu cầu rồi chỉ định courseId, userId và 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;
Truy xuất lời mời
Truy xuất lời mời cụ thể bằng cách gọi phương thức invitations.get() và chỉ định id của lời mời.
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;
Chấp nhận lời mời
Việc chấp nhận lời mời tham gia khoá học sẽ xoá lời mời và thêm người dùng vào khoá học với vai trò được chỉ định trong lời mời. Chấp nhận lời mời bằng cách gọi phương thức invitations.accept() và chỉ định id của lời mời.