अभिभावक बनाना और उन्हें मैनेज करना

Guardian संसाधन, किसी उपयोगकर्ता को दिखाता है. जैसे, माता-पिता को छात्र के कोर्स और उसके कोर्सवर्क की जानकारी मिलती है. आम तौर पर, छात्र के Classroom डोमेन का सदस्य न होने वाले अभिभावक को, उनके ईमेल पते का इस्तेमाल करके न्योता भेजना होगा.

न्योतों को GuardianInvitation रिसॉर्स से दिखाया जाता है. न्योता पाने वाले उपयोगकर्ता को एक ईमेल मिलेगा. इसमें उपयोगकर्ता से न्योता स्वीकार करने के लिए कहा जाएगा. अगर ईमेल पता किसी Google खाते से नहीं जुड़ा है, तो न्योता स्वीकार करने से पहले उपयोगकर्ता को खाता बनाने के लिए कहा जाएगा.

जब उपयोगकर्ता को न्योता भेजा जाता है और वह न्योता स्वीकार नहीं करता, तब GuardianInvitation की स्थिति PENDING होती है. उपयोगकर्ता के न्योता स्वीकार करने के बाद, GuardianInvitation को COMPLETED के तौर पर मार्क कर दिया जाता है. साथ ही, एक Guardian संसाधन बनाया जाता है.

GuardianInvitation की स्थिति को COMPLETED में भी बदला जा सकता है. ऐसा तब होता है, जब न्योते की समयसीमा खत्म हो जाती है या न्योते को कोई ऐसा उपयोगकर्ता रद्द कर देता है जिसके पास अनुमति है. उदाहरण के लिए, PatchGuardianInvitation तरीके का इस्तेमाल करके. अभिभावक, Classroom के शिक्षक या एडमिन, Classroom के वेब ऐप्लिकेशन या DeleteGuardian तरीके का इस्तेमाल करके, अपने बच्चे के साथ संबंध खत्म कर सकते हैं.

अभिभावकों को कौन मैनेज कर सकता है

नीचे दी गई टेबल में, उन कार्रवाइयों के बारे में बताया गया है जिन्हें अभिभावकों के लिए किया जा सकता है. ये कार्रवाइयां, पुष्टि किए गए उपयोगकर्ता के टाइप के हिसाब से की जा सकती हैं:

उपयोगकर्ता टाइप के हिसाब से, अभिभावक से जुड़ी एसीएल की टेबल

स्कोप

अभिभावकों को मैनेज करने के लिए, आपके पास तीन तरह के स्कोप होते हैं:

  • https://www.googleapis.com/auth/classroom.guardianlinks.me.readonly: उपयोगकर्ता के खुद के अभिभावकों की जानकारी देखना.
  • https://www.googleapis.com/auth/classroom.guardianlinks.students.readonly: उन छात्र-छात्राओं के अभिभावकों और अभिभावक बनने के न्योतों को देखना जिन्हें उपयोगकर्ता पढ़ाता है या जिनकी कक्षाओं का वह एडमिन है.
  • https://www.googleapis.com/auth/classroom.guardianlinks.students: उन छात्र-छात्राओं के लिए अभिभावकों और अभिभावक बनने के न्योतों को देखना और मैनेज करना जिन्हें उपयोगकर्ता पढ़ाता है या जिनकी कक्षाओं का वह एडमिन है.

सामान्य कार्रवाइयां

इस सेक्शन में, अभिभावक की कुछ सामान्य कार्रवाइयों के बारे में बताया गया है. ये कार्रवाइयां, Google Classroom API का इस्तेमाल करके की जा सकती हैं.

गार्जियन के लिए न्योता बनाना

नीचे दिए गए उदाहरण में, userProfiles.guardianInvitations.create() तरीके का इस्तेमाल करके, अभिभावक के लिए न्योता बनाने का तरीका बताया गया है:

Java

classroom/snippets/src/main/java/CreateGuardianInvitation.java
GuardianInvitation guardianInvitation = null;

/* Create a GuardianInvitation object with state set to PENDING. See
https://developers.google.com/classroom/reference/rest/v1/userProfiles.guardianInvitations#guardianinvitationstate
for other possible states of guardian invitations. */
GuardianInvitation content =
    new GuardianInvitation()
        .setStudentId(studentId)
        .setInvitedEmailAddress(guardianEmail)
        .setState("PENDING");
try {
  guardianInvitation =
      service.userProfiles().guardianInvitations().create(studentId, content).execute();

  System.out.printf("Invitation created: %s\n", guardianInvitation.getInvitationId());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of studentId: %s", studentId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardianInvitation;

Python

guardianInvitation = {
  'invitedEmailAddress': 'guardian@gmail.com',
}
guardianInvitation = service.userProfiles().guardianInvitations().create(
                      studentId='student@mydomain.edu',
                          body=guardianInvitation).execute()
print("Invitation created with id: {0}".format(guardianInvitation.get('invitationId')))

जवाब में, सर्वर से असाइन किया गया आइडेंटिफ़ायर शामिल होता है. इसका इस्तेमाल, GuardianInvitation को रेफ़र करने के लिए किया जा सकता है.

अभिभावक के लिए भेजा गया न्योता रद्द करना

किसी न्योते को रद्द करने के लिए, userProfiles.guardianInvitations.patch() तरीके को कॉल करके, न्योते की स्थिति को PENDING से COMPLETE में बदलें. न्योता हटाने का यही एक तरीका है.

Java

classroom/snippets/src/main/java/CancelGuardianInvitation.java
GuardianInvitation guardianInvitation = null;

try {
  /* Change the state of the GuardianInvitation from PENDING to COMPLETE. See
  https://developers.google.com/classroom/reference/rest/v1/userProfiles.guardianInvitations#guardianinvitationstate
  for other possible states of guardian invitations. */
  GuardianInvitation content =
      service.userProfiles().guardianInvitations().get(studentId, invitationId).execute();
  content.setState("COMPLETE");

  guardianInvitation =
      service
          .userProfiles()
          .guardianInvitations()
          .patch(studentId, invitationId, content)
          .set("updateMask", "state")
          .execute();

  System.out.printf(
      "Invitation (%s) state set to %s\n.",
      guardianInvitation.getInvitationId(), guardianInvitation.getState());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf(
        "There is no record of studentId (%s) or invitationId (%s).", studentId, invitationId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardianInvitation;

Python

guardian_invite = {
     'state': 'COMPLETE'
}
guardianInvitation = service.userProfiles().guardianInvitations().patch(
  studentId='student@mydomain.edu',
  invitationId=1234, # Replace with the invitation ID of the invitation you want to cancel
  updateMask='state',
  body=guardianInvitation).execute()

किसी छात्र/छात्रा को भेजे गए न्योतों की सूची देखना

userProfiles.guardianInvitations.list() तरीके का इस्तेमाल करके, किसी छात्र/छात्रा को भेजे गए सभी न्योतों की सूची देखी जा सकती है. डिफ़ॉल्ट रूप से, सिर्फ़ PENDING न्योते वापस भेजे जाएंगे. डोमेन एडमिन, states पैरामीटर देकर, COMPLETED स्थिति में मौजूद न्योते भी वापस पा सकता है.

Java

classroom/snippets/src/main/java/ListGuardianInvitationsByStudent.java
List<GuardianInvitation> guardianInvitations = new ArrayList<>();
String pageToken = null;

try {
  do {
    ListGuardianInvitationsResponse response =
        service
            .userProfiles()
            .guardianInvitations()
            .list(studentId)
            .setPageToken(pageToken)
            .execute();

    /* Ensure that the response is not null before retrieving data from it to avoid errors. */
    if (response.getGuardianInvitations() != null) {
      guardianInvitations.addAll(response.getGuardianInvitations());
      pageToken = response.getNextPageToken();
    }
  } while (pageToken != null);

  if (guardianInvitations.isEmpty()) {
    System.out.println("No guardian invitations found.");
  } else {
    for (GuardianInvitation invitation : guardianInvitations) {
      System.out.printf("Guardian invitation id: %s\n", invitation.getInvitationId());
    }
  }
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of studentId (%s).", studentId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardianInvitations;

Python

guardian_invites = []
page_token = None

while True:
    response = service.userProfiles().guardianInvitations().list(
                                      studentId='student@mydomain.edu').execute()
    guardian_invites.extend(response.get('guardian_invites', []))
    page_token = response.get('nextPageToken', None)
    if not page_token:
        break

if not courses:
    print('No guardians invited for this {0}.'.format(response.get('studentId')))
else:
    print('Guardian Invite:')
    for guardian in guardian_invites:
        print('An invite was sent to '.format(guardian.get('id'),
                                              guardian.get('guardianId')))

ऐक्टिव अभिभावकों की सूची

यह पता लगाने के लिए कि किसी छात्र के लिए कौनसे उपयोगकर्ता, ऐक्टिव अभिभावक हैं, userProfiles.guardians.list() तरीके का इस्तेमाल करें. ऐक्टिव अभिभावक वे होते हैं जिन्होंने न्योता स्वीकार कर लिया है.

Java

classroom/snippets/src/main/java/ListGuardians.java
List<Guardian> guardians = new ArrayList<>();
String pageToken = null;

try {
  do {
    ListGuardiansResponse response =
        service.userProfiles().guardians().list(studentId).setPageToken(pageToken).execute();

    /* Ensure that the response is not null before retrieving data from it to avoid errors. */
    if (response.getGuardians() != null) {
      guardians.addAll(response.getGuardians());
      pageToken = response.getNextPageToken();
    }
  } while (pageToken != null);

  if (guardians.isEmpty()) {
    System.out.println("No guardians found.");
  } else {
    for (Guardian guardian : guardians) {
      System.out.printf(
          "Guardian name: %s, guardian id: %s, guardian email: %s\n",
          guardian.getGuardianProfile().getName().getFullName(),
          guardian.getGuardianId(),
          guardian.getInvitedEmailAddress());
    }
  }

} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of studentId (%s).", studentId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return guardians;

Python

guardian_invites = []
page_token = None

while True:
    response = service.userProfiles().guardians().list(studentId='student@mydomain.edu').execute()
    guardian_invites.extend(response.get('guardian_invites', []))
    page_token = response.get('nextPageToken', None)
    if not page_token:
        break

if not courses:
    print('No guardians invited for this {0}.'.format(response.get('studentId')))
else:
    print('Guardian Invite:')
    for guardian in guardian_invites:
        print('An invite was sent to '.format(guardian.get('id'),
                                              guardian.get('guardianId')))

अभिभावकों को हटाना

userProfiles.guardians.delete() तरीके का इस्तेमाल करके, किसी छात्र/छात्रा के खाते से अभिभावक को भी हटाया जा सकता है:

Java

classroom/snippets/src/main/java/DeleteGuardian.java
try {
  service.userProfiles().guardians().delete(studentId, guardianId).execute();
  System.out.printf("The guardian with id %s was deleted.\n", guardianId);
} catch (GoogleJsonResponseException e) {
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("There is no record of guardianId (%s).", guardianId);
  }
}

Python

service.userProfiles().guardians().delete(studentId='student@mydomain.edu',
                                        guardianId='guardian@gmail.com').execute()