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

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

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

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

अगर GuardianInvitation की स्थिति में बदलाव करने की समयसीमा खत्म हो जाती है या अनुमति वाले किसी उपयोगकर्ता ने न्योता रद्द कर दिया है, तो 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()