कोर्स के न्योते मैनेज करना

Classroom में मौजूद Invitation संसाधन, किसी उपयोगकर्ता को किसी कोर्स में शामिल होने का न्योता देता है. इसमें, उपयोगकर्ता को कोर्स में किसी खास भूमिका के साथ शामिल होने का न्योता दिया जाता है. जैसे, छात्र, शिक्षक या मालिक.

हर Invitation संसाधन में ये फ़ील्ड होते हैं:

  • id: न्योते के लिए, Classroom से असाइन किया गया आइडेंटिफ़ायर.
  • userId: उस उपयोगकर्ता का आईडी जिसे कोर्स में शामिल होने का न्योता भेजा गया है.
  • courseId: वह कोर्स जिसका न्योता उपयोगकर्ता को भेजा जा रहा है.
  • role: कोर्स में आमंत्रित उपयोगकर्ता की भूमिका.

न्योता बनाना

invitations.create() तरीके का इस्तेमाल करके, किसी उपयोगकर्ता को किसी खास भूमिका के साथ कोर्स में शामिल होने का न्योता भेजा जा सकता है. अनुरोध के मुख्य हिस्से में Invitation रिसॉर्स शामिल करें और courseId, userId, और role की जानकारी दें.

Java
classroom/snippets/src/main/java/CreateInvitation.java
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;

न्योता वापस पाना

invitations.get() तरीके को कॉल करके और न्योते का id बताकर, किसी खास न्योते को वापस पाएं.

Java
classroom/snippets/src/main/java/GetInvitation.java
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;

न्योता स्वीकार करना

न्योता स्वीकार करने पर, न्योता मिट जाता है और न्योते में बताई गई भूमिका के साथ, न्योता पाने वाले उपयोगकर्ता को कोर्स में जोड़ दिया जाता है. invitations.accept() तरीके को कॉल करके और न्योते का id बताकर, न्योता स्वीकार करें.

Java
classroom/snippets/src/main/java/AcceptInvitation.java
try {
  service.invitations().accept(id).execute();
  System.out.printf("Invitation (%s) was accepted.\n", id);
} 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;
}

न्योता मिटाना

न्योते को अपडेट करने का एक ही तरीका है. इसके लिए, न्योते को मिटाएं और नया न्योता बनाएं. न्योते को मिटाने के लिए, invitations.delete() वाले तरीके को कॉल करें और id की जानकारी दें.

Java
classroom/snippets/src/main/java/DeleteInvitation.java
try {
  service.invitations().delete(id).execute();
  System.out.printf("Invitation (%s) was deleted.\n", id);
} 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;
}