จัดการงานหลักสูตรและคะแนน

UI ของ Classroom รองรับงานของชั้นเรียน 5 ประเภท ได้แก่ งาน งานแบบทดสอบ, คำถามที่ต้องการคำตอบสั้นๆ, คำถามแบบหลายตัวเลือก และเนื้อหา ปัจจุบัน Classroom API รองรับประเภทเหล่านี้ 3 ประเภท ซึ่งเรียกว่า CourseWorkType สำหรับ API ได้แก่ Assignments คำถามที่ต้องการคำตอบสั้นๆ และคำถามแบบหลายตัวเลือก

หากต้องการเข้าถึงฟังก์ชันนี้ คุณสามารถใช้แหล่งข้อมูลของหลักสูตร ซึ่งจะแสดงงานหรือคำถามที่มอบหมายให้นักเรียนในหลักสูตรหนึ่ง รวมถึงเอกสารและรายละเอียดเพิ่มเติม เช่น วันที่ครบกำหนดหรือคะแนนสูงสุด

นอกเหนือจากทรัพยากรใน CourseWork แล้ว คุณยังจัดการงานที่เสร็จสมบูรณ์แล้วด้วยทรัพยากร StudentSubmission ได้อีกด้วย ส่วนต่อไปนี้จะอธิบายลักษณะนี้ โดยละเอียดยิ่งขึ้น

สร้างงาน

คุณสร้างงานในนามของครูของหลักสูตรได้เท่านั้น และการพยายามสร้างงานในหลักสูตรในนามของนักเรียนจะทำให้เกิดข้อผิดพลาด 403 PERMISSION_DENIED ในทำนองเดียวกัน ผู้ดูแลระบบโดเมนไม่สามารถสร้างงานสำหรับหลักสูตรที่ไม่ได้สอน และการพยายามทำเช่นนั้นผ่าน API จะทำให้เกิดข้อผิดพลาด 403 PERMISSION_DENIED เช่นกัน

เมื่อสร้างงานโดยใช้เมธอด courses.courseWork.create คุณจะแนบลิงก์เป็น materials ได้ดังที่แสดงในโค้ดตัวอย่างด้านล่าง

Java

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;

Python

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)

ผลลัพธ์จะมีตัวระบุที่เซิร์ฟเวอร์กำหนดซึ่งใช้เพื่ออ้างอิงการกำหนดในคำขอ API อื่นๆ ได้

หากต้องการรวมสื่อการสอนที่ลิงก์ไว้ในงานที่สร้างผ่าน Classroom API ให้ใช้ทรัพยากรลิงก์โดยระบุ URL เป้าหมาย Classroom จะดึงข้อมูลชื่อและภาพขนาดย่อโดยอัตโนมัติ Classroom API ยังรองรับเนื้อหาของ Google ไดรฟ์และ YouTube อยู่แล้ว ซึ่งมาพร้อมกับทรัพยากร DriveFile หรือทรัพยากรวิดีโอ YouTube ได้ด้วยวิธีที่คล้ายกัน

หากต้องการระบุวันที่ครบกำหนด ให้ตั้งค่าช่อง dueDate และ dueTime ให้เป็นเวลา UTC ที่สอดคล้องกัน วันที่ครบกำหนดจะต้องเป็นวันที่ในอนาคต

เรียกข้อมูลงานและคำถาม

คุณเรียกดูงานและคำถามสำหรับนักเรียนและครูในหลักสูตรที่เกี่ยวข้องหรือโดยผู้ดูแลระบบโดเมนได้ หากต้องการเรียกดูงานหรือคำถามที่เจาะจง ให้ใช้ Course.courseWork.get หากต้องการเรียกดูงานหรือคำถามทั้งหมด (อาจจะตรงตามเกณฑ์บางอย่าง) ให้ใช้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

การมีสิทธิ์ในการเรียกข้อมูลงานหรือคำถามไม่ได้บอกเป็นนัยถึงสิทธิ์ในการเข้าถึงเนื้อหาหรือข้อมูลเมตาของเนื้อหา ในทางปฏิบัติ ผู้ดูแลระบบอาจไม่เห็นชื่อไฟล์ในไดรฟ์ที่แนบมาหากไม่ได้เป็นสมาชิกของหลักสูตร หากต้องการอนุญาตให้ผู้ดูแลระบบเข้าถึงไฟล์ของผู้ใช้ได้ โปรดดูคู่มือการมอบสิทธิ์ทั่วทั้งโดเมน

จัดการคำตอบของนักเรียน

ทรัพยากร StudentSubmission หมายถึงงานที่ทำเสร็จและคะแนนสำหรับงานหรือคำถามของนักเรียน ระบบจะสร้างทรัพยากร StudentSubmission โดยปริยายสำหรับนักเรียนแต่ละคนเมื่อมีการสร้างคำถามหรืองานใหม่

ส่วนต่อไปนี้จะอธิบายการดำเนินการทั่วไปที่จัดการคำตอบของนักเรียน

ดึงคำตอบของนักเรียน

นักเรียนสามารถเรียกข้อมูลงานของตนเอง ครูสามารถเรียกข้อมูลงานของนักเรียนทุกคนในหลักสูตร และผู้ดูแลระบบโดเมนสามารถเรียกข้อมูลงานที่ส่งทั้งหมดสำหรับนักเรียนทุกคนในโดเมน งานที่นักเรียนส่งแต่ละครั้งจะได้รับตัวระบุ ถ้าคุณทราบตัวระบุ ให้ใช้ courses.courseWork.studentSubmissions.get เพื่อดึงข้อมูลนั้น

ใช้เมธอด courses.courseWork.studentSubmissions.list เพื่อดูทรัพยากร StudentSubmission ที่ตรงกับเกณฑ์บางอย่างดังที่แสดงในตัวอย่างต่อไปนี้

Java

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;

Python

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)

เรียกดูทรัพยากร StudentSubmission ที่เป็นของนักเรียนคนหนึ่งโดยระบุพารามิเตอร์ userId ตามที่แสดงในตัวอย่างต่อไปนี้

Java

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());
    }
  }

Python

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")

ระบบจะระบุนักเรียนโดยใช้รหัสที่ไม่ซ้ำกันหรืออีเมลของผู้ใช้ตามที่ Google Admin SDK ส่งคืนให้ ผู้ใช้ปัจจุบันอาจอ้างอิงรหัสของตนเองโดยใช้ชวเลข "me" ด้วย

นอกจากนี้ คุณยังสามารถรับงานที่นักเรียนส่งสำหรับงานทั้งหมดในหลักสูตรหนึ่งได้ด้วย ในการดำเนินการดังกล่าว ให้ใช้ "-" ตามตัวอักษรเป็น courseWorkId ตามที่แสดงในตัวอย่างต่อไปนี้

Java

service.courses().courseWork().studentSubmissions()
    .list(courseId, "-")
    .set("userId", userId)
    .execute();

Python

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

สิทธิ์ในการเรียกข้อมูลงานที่นักเรียนส่งไม่ได้บอกเป็นนัยถึงสิทธิ์เข้าถึงไฟล์แนบหรือข้อมูลเมตาของไฟล์แนบ ในทางปฏิบัติ ผู้ดูแลระบบอาจไม่เห็นชื่อไฟล์ในไดรฟ์ที่แนบมาหากไม่ได้เป็นสมาชิกของหลักสูตร หากต้องการอนุญาตให้ผู้ดูแลระบบเข้าถึงไฟล์ของผู้ใช้ โปรดดูคู่มือการมอบสิทธิ์ทั่วทั้งโดเมน

การเพิ่มไฟล์แนบในคำตอบของนักเรียน

คุณแนบลิงก์ไปกับงานที่นักเรียนส่งได้โดยแนบทรัพยากร Link, DriveFile หรือ YouTubeVideo ซึ่งทำได้ด้วย courses.courseWork.studentSubmissions.modifyAttachments ดังที่แสดงในตัวอย่างต่อไปนี้

Java

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;

Python

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")

ไฟล์แนบของลิงก์จะกำหนดโดย URL เป้าหมาย Classroom จะดึงข้อมูลชื่อและภาพขนาดย่อโดยอัตโนมัติ คุณดูเนื้อหาอื่นๆ ได้ที่หน้าอ้างอิงที่เกี่ยวข้อง

เฉพาะครูหรือนักเรียนที่เป็นเจ้าของหลักสูตรเท่านั้นที่แก้ไข StudentSubmission ได้ คุณจะแนบ Materials ได้เฉพาะในกรณีที่ CourseWorkType งานที่นักเรียนส่งคือ ASSIGNMENT

ขอบเขตที่จำเป็นจะขึ้นอยู่กับบทบาทที่ผู้ใช้ที่ส่งคำขอมีในหลักสูตร ใช้ขอบเขตต่อไปนี้หากผู้ใช้เป็นครู

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

ใช้ขอบเขตต่อไปนี้หากผู้ใช้เป็นนักเรียน

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

จัดการสถานะคำตอบของนักเรียน

นักเรียนอาจยกเลิกการส่ง ส่ง หรือส่งคืนคำตอบได้ ช่องสถานะใน StudentSubmission แสดงถึงสถานะปัจจุบัน ในการเปลี่ยนสถานะ ให้เรียกใช้ วิธีใดวิธีหนึ่งต่อไปนี้

เมธอดทั้งหมดนี้ใช้เนื้อความว่างเปล่า ตัวอย่าง

Java

classroom/snippets/src/main/java/ReturnStudentSubmission.java
try {
  service
      .courses()
      .courseWork()
      .studentSubmissions()
      .classroomReturn(courseId, courseWorkId, id, null)
      .execute();
} 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;
}

Python

service.courses().courseWork().studentSubmission().turnIn(
    courseId=<course ID or alias>,
    courseWorkId=<courseWork ID>,
    id=<studentSubmission ID>,
    body={}).execute()

เฉพาะนักเรียนที่เป็นเจ้าของ StudentSubmission เท่านั้นที่สามารถส่งหรือเรียกคืนได้ เฉพาะงานที่ส่งแล้วเท่านั้นที่สามารถเรียกคืนได้ ครูผู้สอนของหลักสูตรจะส่งคืน StudentSubmission ที่อยู่ในสถานะ "ส่งแล้ว" ได้เท่านั้น

ให้คะแนนคำตอบของนักเรียน

แหล่งข้อมูล StudentSubmission มีช่องสำหรับจัดเก็บคะแนน 2 ช่อง ได้แก่ assignedGrade ซึ่งเป็นคะแนนที่รายงานให้นักเรียน และ draftGrade ซึ่งเป็นคะแนนคร่าวๆ ที่จะปรากฏต่อครูเท่านั้น ช่องเหล่านี้จะอัปเดตโดยใช้ courses.courseWork.studentSubmissions.patch กับฟิลด์มาสก์ที่มีช่องที่เหมาะสม ดังที่แสดงในตัวอย่างต่อไปนี้

Java

classroom/snippets/src/main/java/PatchStudentSubmission.java
StudentSubmission studentSubmission = null;
try {
  // Updating the draftGrade and assignedGrade fields for the specific student submission.
  StudentSubmission content =
      service
          .courses()
          .courseWork()
          .studentSubmissions()
          .get(courseId, courseWorkId, id)
          .execute();
  content.setAssignedGrade(90.00);
  content.setDraftGrade(80.00);

  // The updated studentSubmission object is returned with the new draftGrade and assignedGrade.
  studentSubmission =
      service
          .courses()
          .courseWork()
          .studentSubmissions()
          .patch(courseId, courseWorkId, id, content)
          .set("updateMask", "draftGrade,assignedGrade")
          .execute();

  /* Prints the updated student submission. */
  System.out.printf(
      "Updated student submission draft grade (%s) and assigned grade (%s).\n",
      studentSubmission.getDraftGrade(), studentSubmission.getAssignedGrade());
} 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;

Python

studentSubmission = {
  'assignedGrade': 99,
  'draftGrade': 80
}
service.courses().courseWork().studentSubmissions().patch(
    courseId=<course ID or alias>,
    courseWorkId=<courseWork ID>,
    id=<studentSubmission ID>,
    updateMask='assignedGrade,draftGrade',
    body=studentSubmission).execute()

เมื่อใช้ UI ของ Classroom ครูจะให้คะแนนไม่ได้จนกว่าจะบันทึกคะแนนคร่าวๆ ก่อน แล้วระบบจึงส่งคืนคะแนนให้นักเรียน ได้ แอปพลิเคชันต้องจำลองลักษณะการทำงานนี้ แอปพลิเคชันสามารถให้คะแนนงานของนักเรียนโดยใช้ 1 ใน 2 วิธีต่อไปนี้

  • มอบหมายเฉพาะ draftGrade วิธีนี้มีประโยชน์ เช่น ทำให้ครูตรวจคะแนนด้วยตนเองก่อนสรุปเกรดได้ นักเรียนจะไม่เห็นคะแนนคร่าวๆ

  • มอบหมายทั้ง draftGrade และ assignedGrade เพื่อให้คะแนนงานอย่างสมบูรณ์

แสดงรายการคะแนนที่มอบหมาย

คุณจะแสดงคะแนนทั้งหมดของรายการการบ้านและรายงานบางรายการได้โดยการสำรวจออบเจ็กต์คำตอบของเมธอด courses.courseWork.studentSubmissions.list ดังนี้

Java

classroom/snippets/src/main/java/ListStudentSubmissions.java
  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 submissions found.");
} else {
  for (StudentSubmission submission : studentSubmissions) {
    System.out.printf(
        "User ID %s, Assigned grade: %s\n",
        submission.getUserId(), submission.getAssignedGrade());
  }
}

Python

response = coursework.studentSubmissions().list(
    courseId=course_id,
    courseWorkId=coursework_id,
    pageSize=10).execute()
submissions.extend(response.get('studentSubmissions', []))

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

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