कोर्सवर्क मैनेज करना

Classroom ऐप्लिकेशन में तीन तरह के स्ट्रीम आइटम इस्तेमाल किए जा सकते हैं: CourseWork, CourseWorkMaterials, और Announcements. इस गाइड में, CourseWork को मैनेज करने का तरीका बताया गया है. हालांकि, सभी स्ट्रीम आइटम के एपीआई एक जैसे होते हैं. स्ट्रीम आइटम के टाइप और उनके अंतर के बारे में ज़्यादा जानने के लिए, एपीआई संसाधन देखें.

CourseWork रिसॉर्स, किसी खास कोर्स में छात्रों को असाइन किए गए वर्क आइटम के बारे में बताता है. इसमें, अतिरिक्त कॉन्टेंट और जानकारी भी शामिल होती है. जैसे, सबमिट करने की आखिरी तारीख या ज़्यादा से ज़्यादा मिलने वाले अंक. CourseWork के चार सब-टाइप होते हैं: असाइनमेंट, क्विज़ असाइनमेंट, छोटे जवाब वाले सवाल, और एक से ज़्यादा जवाब वाले सवाल. Classroom API, इनमें से तीन सब-टाइप के साथ काम करता है: असाइनमेंट, छोटे जवाब वाले सवाल, और जवाबों के कई विकल्प वाले सवाल. इन टाइप को CourseWork.workType फ़ील्ड से दिखाया जाता है.

CourseWork संसाधन के अलावा, StudentSubmission संसाधन की मदद से, पूरे हो चुके काम को मैनेज किया जा सकता है.

कोर्सवर्क बनाना

CourseWork कोर्स के शिक्षक की ओर से सिर्फ़ बनाया जा सकता है. किसी छात्र या ऐसे डोमेन एडमिन की ओर से CourseWork बनाने की कोशिश करने पर जो कोर्स में शिक्षक नहीं है, तो आपको PERMISSION_DENIED गड़बड़ी का मैसेज दिखेगा. Classroom में अलग-अलग भूमिकाओं के बारे में ज़्यादा जानने के लिए, उपयोगकर्ताओं के टाइप लेख पढ़ें.

courses.courseWork.create तरीके का इस्तेमाल करके CourseWork बनाते समय, लिंक को materials के तौर पर अटैच किया जा सकता है. इस बारे में यहां दिए गए सैंपल कोड में बताया गया है:

JavaPython
classroom/snippets/src/main/java/CreateCourseWork.java
CourseWork courseWork = null;
try {
  // Create a link to add as a material on course work.
  Link articleLink =
      new Link()
          .setTitle("SR-71 Blackbird")
          .setUrl("https://www.lockheedmartin.com/en-us/news/features/history/blackbird.html");

  // Create a list of Materials to add to course work.
  List<Material> materials = Arrays.asList(new Material().setLink(articleLink));

  /* Create new CourseWork object with the material attached.
  Set workType to `ASSIGNMENT`. Possible values of workType can be found here:
  https://developers.google.com/classroom/reference/rest/v1/CourseWorkType
  Set state to `PUBLISHED`. Possible values of state can be found here:
  https://developers.google.com/classroom/reference/rest/v1/courses.courseWork#courseworkstate */
  CourseWork content =
      new CourseWork()
          .setTitle("Supersonic aviation")
          .setDescription(
              "Read about how the SR-71 Blackbird, the world’s fastest and "
                  + "highest-flying manned aircraft, was built.")
          .setMaterials(materials)
          .setWorkType("ASSIGNMENT")
          .setState("PUBLISHED");

  courseWork = service.courses().courseWork().create(courseId, content).execute();

  /* Prints the created courseWork. */
  System.out.printf("CourseWork created: %s\n", courseWork.getTitle());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf("The courseId does not exist: %s.\n", courseId);
  } else {
    throw e;
  }
  throw e;
} catch (Exception e) {
  throw e;
}
return courseWork;
classroom/snippets/classroom_create_coursework.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def classroom_create_coursework(course_id):
  """
  Creates the coursework the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """

  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member

  try:
    service = build("classroom", "v1", credentials=creds)
    coursework = {
        "title": "Ant colonies",
        "description": """Read the article about ant colonies
                              and complete the quiz.""",
        "materials": [
            {"link": {"url": "http://example.com/ant-colonies"}},
            {"link": {"url": "http://example.com/ant-quiz"}},
        ],
        "workType": "ASSIGNMENT",
        "state": "PUBLISHED",
    }
    coursework = (
        service.courses()
        .courseWork()
        .create(courseId=course_id, body=coursework)
        .execute()
    )
    print(f"Assignment created with ID {coursework.get('id')}")
    return coursework

  except HttpError as error:
    print(f"An error occurred: {error}")
    return error


if __name__ == "__main__":
  # Put the course_id of course whose coursework needs to be created,
  # the user has access to.
  classroom_create_coursework(453686957652)

title और workType फ़ील्ड की वैल्यू देना ज़रूरी है. बाकी सभी फ़ील्ड ज़रूरी नहीं हैं. अगर state की वैल्यू नहीं दी गई है, तो CourseWork को ड्राफ़्ट के तौर पर बनाया जाता है.

CourseWork में लिंक किए गए कॉन्टेंट को शामिल करने के लिए, किसी टारगेट के साथ लिंक किए गए संसाधन का इस्तेमाल करेंurl. Classroom, title और थंबनेल इमेज के यूआरएल (thumbnailUrl) को अपने-आप फ़ेच करता है. Classroom API, Google Drive और YouTube के कॉन्टेंट के साथ भी काम करता है. इन्हें DriveFile resource या YouTubeVideo resource के साथ उसी तरह शामिल किया जा सकता है.

पेमेंट की आखिरी तारीख तय करने के लिए, dueDate और dueTime फ़ील्ड को यूटीसी समय पर सेट करें. पेमेंट की तारीख, आने वाले समय की होनी चाहिए.

CourseWork रिस्पॉन्स में, सर्वर से असाइन किया गया आइडेंटिफ़ायर शामिल होता है. इसका इस्तेमाल, अन्य एपीआई अनुरोधों में असाइनमेंट का रेफ़रंस देने के लिए किया जा सकता है.

कोर्सवर्क वापस पाना

आपके पास उस कोर्स के छात्र-छात्राओं और शिक्षकों की ओर से CourseWork को वापस पाने का विकल्प है. डोमेन एडमिन की ओर से भी CourseWork को वापस पाया जा सकता है. भले ही, वे कोर्स में शिक्षक न हों. किसी खास CourseWork को वापस पाने के लिए, courses.courseWork.get का इस्तेमाल करें. सभी CourseWork (ज़रूरी नहीं कि वे कुछ शर्तों को पूरा करते हों) को वापस पाने के लिए, courses.courseWork.list का इस्तेमाल करें.

ज़रूरी दायरा, कोर्स में अनुरोध करने वाले उपयोगकर्ता की भूमिका पर निर्भर करता है. अगर उपयोगकर्ता छात्र या छात्रा है, तो इनमें से किसी एक स्कोप का इस्तेमाल करें:

  • https://www.googleapis.com/auth/classroom.coursework.me.readonly
  • https://www.googleapis.com/auth/classroom.coursework.me

अगर उपयोगकर्ता शिक्षक या डोमेन एडमिन है, तो इनमें से किसी एक स्कोप का इस्तेमाल करें:

  • https://www.googleapis.com/auth/classroom.coursework.students.readonly
  • https://www.googleapis.com/auth/classroom.coursework.students

CourseWork को वापस पाने की अनुमति होने का मतलब यह नहीं है कि आपके पास कॉन्टेंट या कॉन्टेंट के मेटाडेटा को ऐक्सेस करने की अनुमति है. इसका मतलब है कि अगर कोई एडमिन कोर्स का सदस्य नहीं है, तो हो सकता है कि उसे अटैच की गई Drive फ़ाइल का टाइटल न दिखे.

छात्र-छात्राओं के जवाब मैनेज करना

StudentSubmission रिसॉर्स से पता चलता है कि किसी CourseWork के लिए छात्र/छात्रा ने क्या काम किया है. संसाधन में, काम से जुड़ा मेटाडेटा शामिल होता है. जैसे, काम की स्थिति और ग्रेड. नया CourseWork बनाने पर, हर छात्र/छात्रा के लिए StudentSubmission अपने-आप बन जाता है.

यहां दिए गए सेक्शन में, छात्र-छात्राओं के जवाबों को मैनेज करने वाली सामान्य कार्रवाइयों के बारे में बताया गया है.

छात्र-छात्राओं के जवाब पाना

छात्र/छात्राएं अपने सबमिशन वापस पा सकते हैं. शिक्षक, अपने कोर्स में शामिल सभी छात्र/छात्राओं के सबमिशन वापस पा सकते हैं. साथ ही, डोमेन एडमिन अपने डोमेन में शामिल सभी छात्र/छात्राओं के सबमिशन वापस पा सकते हैं. हर StudentSubmission को एक आइडेंटिफ़ायर असाइन किया जाता है. अगर आपको आइडेंटिफ़ायर पता है, तो सबमिट किए गए डेटा को वापस पाने के लिए, courses.courseWork.studentSubmissions.get का इस्तेमाल करें.

courses.courseWork.studentSubmissions.list तरीके का इस्तेमाल करके, कुछ शर्तों से मैच करने वाले सभी StudentSubmission संसाधन पाएं. इसका उदाहरण यहां दिया गया है:

JavaPython
classroom/snippets/src/main/java/ListSubmissions.java
List<StudentSubmission> studentSubmissions = new ArrayList<>();
String pageToken = null;

try {
  do {
    ListStudentSubmissionsResponse response =
        service
            .courses()
            .courseWork()
            .studentSubmissions()
            .list(courseId, courseWorkId)
            .setPageToken(pageToken)
            .execute();

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

  if (studentSubmissions.isEmpty()) {
    System.out.println("No student submission found.");
  } else {
    for (StudentSubmission submission : studentSubmissions) {
      System.out.printf(
          "Student id (%s), student submission id (%s)\n",
          submission.getUserId(), submission.getId());
    }
  }
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf(
        "The courseId (%s) or courseWorkId (%s) does not exist.\n", courseId, courseWorkId);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return studentSubmissions;
classroom/snippets/classroom_list_submissions.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def classroom_list_submissions(course_id, coursework_id):
  """
  Creates the courses the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """

  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  submissions = []
  page_token = None

  try:
    service = build("classroom", "v1", credentials=creds)
    while True:
      coursework = service.courses().courseWork()
      response = (
          coursework.studentSubmissions()
          .list(
              pageToken=page_token,
              courseId=course_id,
              courseWorkId=coursework_id,
              pageSize=10,
          )
          .execute()
      )
      submissions.extend(response.get("studentSubmissions", []))
      page_token = response.get("nextPageToken", None)
      if not page_token:
        break

    if not submissions:
      print("No student submissions found.")

    print("Student Submissions:")
    for submission in submissions:
      print(
          "Submitted at:"
          f"{(submission.get('id'), submission.get('creationTime'))}"
      )

  except HttpError as error:
    print(f"An error occurred: {error}")
    submissions = None
  return submissions


if __name__ == "__main__":
  # Put the course_id and coursework_id of course whose list needs to be
  # submitted.
  classroom_list_submissions(453686957652, 466086979658)

userId पैरामीटर की मदद से, किसी खास छात्र के StudentSubmission संसाधनों को पाएं. इसका उदाहरण नीचे दिया गया है:

JavaPython
classroom/snippets/src/main/java/ListStudentSubmissions.java
List<StudentSubmission> studentSubmissions = new ArrayList<>();
String pageToken = null;

try {
  do {
    // Set the userId as a query parameter on the request.
    ListStudentSubmissionsResponse response =
        service
            .courses()
            .courseWork()
            .studentSubmissions()
            .list(courseId, courseWorkId)
            .setPageToken(pageToken)
            .set("userId", userId)
            .execute();

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

  if (studentSubmissions.isEmpty()) {
    System.out.println("No student submission found.");
  } else {
    for (StudentSubmission submission : studentSubmissions) {
      System.out.printf("Student submission: %s.\n", submission.getId());
    }
  }
classroom/snippets/classroom_list_student_submissions.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def classroom_list_student_submissions(course_id, coursework_id, user_id):
  """
  Creates the courses the user has access to.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """

  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  submissions = []
  page_token = None

  try:
    service = build("classroom", "v1", credentials=creds)
    while True:
      coursework = service.courses().courseWork()
      response = (
          coursework.studentSubmissions()
          .list(
              pageToken=page_token,
              courseId=course_id,
              courseWorkId=coursework_id,
              userId=user_id,
          )
          .execute()
      )
      submissions.extend(response.get("studentSubmissions", []))
      page_token = response.get("nextPageToken", None)
      if not page_token:
        break

    if not submissions:
      print("No student submissions found.")

    print("Student Submissions:")
    for submission in submissions:
      print(
          "Submitted at:"
          f"{(submission.get('id'), submission.get('creationTime'))}"
      )

  except HttpError as error:
    print(f"An error occurred: {error}")
  return submissions


if __name__ == "__main__":
  # Put the course_id, coursework_id and user_id of course whose list needs
  # to be submitted.
  classroom_list_student_submissions(453686957652, 466086979658, "me")

छात्र-छात्राओं की पहचान, यूनीक आईडी या ईमेल पते से की जाती है. इसकी जानकारी, Student रिसॉर्स में दी गई है. मौजूदा उपयोगकर्ता, "me" शॉर्टहैंड का इस्तेमाल करके अपने आईडी का रेफ़रंस भी दे सकता है.

किसी कोर्स में मौजूद सभी असाइनमेंट के लिए, छात्र-छात्राओं के सबमिट किए गए काम भी वापस पाए जा सकते हैं. ऐसा करने के लिए, courseWorkId के तौर पर लिटरल "-" का इस्तेमाल करें, जैसा कि इस सैंपल में दिखाया गया है:

JavaPython
service.courses().courseWork().studentSubmissions()
    .list(courseId, "-")
    .set("userId", userId)
    .execute();
service.courses().courseWork().studentSubmissions().list(
    courseId=<course ID or alias>,
    courseWorkId='-',
    userId=<user ID>).execute()

ज़रूरी दायरा, कोर्स में अनुरोध करने वाले उपयोगकर्ता की भूमिका पर निर्भर करता है. अगर उपयोगकर्ता शिक्षक या डोमेन एडमिन है, तो इस स्कोप का इस्तेमाल करें:

  • https://www.googleapis.com/auth/classroom.coursework.students.readonly
  • https://www.googleapis.com/auth/classroom.coursework.students

अगर उपयोगकर्ता छात्र या छात्रा है, तो इस स्कोप का इस्तेमाल करें:

  • https://www.googleapis.com/auth/classroom.coursework.me.readonly
  • https://www.googleapis.com/auth/classroom.coursework.me

StudentSubmission को वापस पाने की अनुमति होने का मतलब यह नहीं है कि आपके पास अटैचमेंट या अटैचमेंट के मेटाडेटा को ऐक्सेस करने की अनुमतियां भी हैं. इसका मतलब है कि अगर एडमिन कोर्स का सदस्य नहीं है, तो हो सकता है कि उसे अटैच की गई Drive फ़ाइल का टाइटल न दिखे.

छात्र के जवाब में अटैचमेंट जोड़ना

छात्र-छात्राओं के सबमिट किए गए काम में लिंक अटैच किए जा सकते हैं. इसके लिए, Link, DriveFile या YouTubeVideo संसाधन अटैच करें. ऐसा करने के लिए, courses.courseWork.studentSubmissions.modifyAttachments का इस्तेमाल किया जाता है. इसका उदाहरण यहां दिया गया है:

JavaPython
classroom/snippets/src/main/java/ModifyAttachmentsStudentSubmission.java
StudentSubmission studentSubmission = null;
try {
  // Create ModifyAttachmentRequest object that includes a new attachment with a link.
  Link link = new Link().setUrl("https://en.wikipedia.org/wiki/Irrational_number");
  Attachment attachment = new Attachment().setLink(link);
  ModifyAttachmentsRequest modifyAttachmentsRequest =
      new ModifyAttachmentsRequest().setAddAttachments(Arrays.asList(attachment));

  // The modified studentSubmission object is returned with the new attachment added to it.
  studentSubmission =
      service
          .courses()
          .courseWork()
          .studentSubmissions()
          .modifyAttachments(courseId, courseWorkId, id, modifyAttachmentsRequest)
          .execute();

  /* Prints the modified student submission. */
  System.out.printf(
      "Modified student submission attachments: '%s'.\n",
      studentSubmission.getAssignmentSubmission().getAttachments());
} catch (GoogleJsonResponseException e) {
  // TODO (developer) - handle error appropriately
  GoogleJsonError error = e.getDetails();
  if (error.getCode() == 404) {
    System.out.printf(
        "The courseId (%s), courseWorkId (%s), or studentSubmissionId (%s) does "
            + "not exist.\n",
        courseId, courseWorkId, id);
  } else {
    throw e;
  }
} catch (Exception e) {
  throw e;
}
return studentSubmission;
classroom/snippets/classroom_add_attachment.py
def classroom_add_attachment(course_id, coursework_id, submission_id):
  """
  Adds attachment to existing course with specific course_id.
  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  # pylint: disable=maybe-no-member
  request = {
      "addAttachments": [
          {"link": {"url": "http://example.com/quiz-results"}},
          {"link": {"url": "http://example.com/quiz-reading"}},
      ]
  }

  try:
    service = build("classroom", "v1", credentials=creds)
    while True:
      coursework = service.courses().courseWork()
      coursework.studentSubmissions().modifyAttachments(
          courseId=course_id,
          courseWorkId=coursework_id,
          id=submission_id,
          body=request,
      ).execute()

  except HttpError as error:
    print(f"An error occurred: {error}")


if __name__ == "__main__":
  # Put the course_id, coursework_id and submission_id of course in which
  # attachment needs to be added.
  classroom_add_attachment("course_id", "coursework_id", "me")

Link अटैचमेंट को टारगेट url से तय किया जाता है. Classroom, title और थंबनेल इमेज (thumbnailUrl) को अपने-आप फ़ेच करता है. StudentSubmissions से अटैच किए जा सकने वाले कॉन्टेंट के बारे में जानने के लिए, Material देखें.

StudentSubmission में सिर्फ़ कोर्स के शिक्षक या उस छात्र/छात्रा के पास बदलाव करने का विकल्प होता है जिसके पास उसका मालिकाना हक होता है. Materials सिर्फ़ तब अटैच किया जा सकता है, जब StudentSubmission का CourseWorkType ASSIGNMENT हो.

ज़रूरी दायरा, कोर्स में अनुरोध करने वाले उपयोगकर्ता की भूमिका पर निर्भर करता है. अगर उपयोगकर्ता शिक्षक है, तो इस स्कोप का इस्तेमाल करें:

  • https://www.googleapis.com/auth/classroom.coursework.students

अगर उपयोगकर्ता छात्र या छात्रा है, तो इस स्कोप का इस्तेमाल करें:

  • https://www.googleapis.com/auth/classroom.coursework.me