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

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

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

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

कोई न्योता बनाना

The 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;
}