สร้างไฟล์แนบนอก Google Classroom

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

ขั้นตอนการทำงาน

เส้นทางการสร้างไฟล์แนบในระดับสูงจะมีลำดับดังนี้

  1. ผู้ใช้ที่เป็นครูเปิดเว็บไซต์หรือแอปของคุณ จากนั้นจึงเลือกเนื้อหาเพื่อมอบหมายให้กับนักเรียน
  2. ตรวจสอบว่าผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้
  3. หากผู้ใช้สร้างไฟล์แนบของส่วนเสริมไม่ได้ ให้สร้างงานของ CourseWorkโดยใส่ URL ไปยังเนื้อหาที่เลือกเป็นสื่อของลิงก์
  4. หากผู้ใช้สามารถสร้างไฟล์แนบของส่วนเสริม ให้ทำตามขั้นตอนต่อไปนี้
    1. สร้างงาน
    2. สร้างไฟล์แนบของส่วนเสริมที่ลิงก์ไปยังเนื้อหาที่เลือก และเชื่อมโยงกับงานใหม่
    3. แจ้งให้ครูทราบว่าสร้างงานเรียบร้อยแล้ว

การดำเนินการแต่ละรายการจะอธิบายไว้ในส่วนต่อไปนี้

ตรวจสอบว่าผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้หรือไม่

คุณสร้างไฟล์แนบของส่วนเสริมในนามของผู้ใช้ที่มีสิทธิ์ได้ ผู้ใช้ที่มีสิทธิ์คือผู้ใช้ที่เป็นครูในหลักสูตรที่คุณพยายามสร้างงานในหลักสูตรและได้รับมอบหมายใบอนุญาตรุ่น Teaching and Learning หรือ Education Plus สำหรับผู้ใช้ดังกล่าว

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

Python

eligibility_response = (
  classroom_service.courses()
  .checkAddOnCreationEligibility(courseId=course_id)
  .execute()
)
is_create_attachment_eligible = (
  eligibility_response.get('isCreateAttachmentEligible')
)
print(f'User eligibility for course {eligibility_response.get("courseId")}'
      f': {is_create_attachment_eligible}.')

หากผู้ใช้มีสิทธิ์ การตอบกลับจะมีค่า isCreateAttachmentEligible บูลีนที่ตั้งค่าเป็น true หากผู้ใช้ไม่มีสิทธิ์ การตอบสนองจะไม่แสดงบูลีน isCreateAttachmentEligible

กำหนดเส้นทางผู้ใช้ตามการมีสิทธิ์

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

ผู้ใช้ที่ไม่มีสิทธิ์

หากผู้ใช้สร้างไฟล์แนบของส่วนเสริมไม่ได้ ให้สร้างงาน CourseWork ใหม่โดยกำหนด URL ของเนื้อหาที่ผู้ใช้เลือกเป็น Link

Python

if not is_create_attachment_eligible:
  coursework = {
    'title': 'My CourseWork Assignment with Link Material',
    'description': 'Created using the Classroom CourseWork API.',
    'workType': 'ASSIGNMENT',
    'state': 'DRAFT',  # Set to 'PUBLISHED' to assign to students.
    'maxPoints': 100,
    'materials': [
      {'link': {'url': my_content_url}}
    ]
  }

  assignment = (
    service.courses()
    .courseWork()
    .create(courseId=course_id, body=coursework)
    .execute()
  )

  print(
    f'Link Material assignment created with ID: {assignment.get("id")}'
  )

คำตอบจะมีงานในหลักสูตรที่ขอพร้อมเนื้อหาที่แนบมา ผู้ใช้จะคลิก Link เพื่อเปิดเนื้อหาในเว็บไซต์ในแท็บใหม่ได้

ร่างงานใน CourseWork โดยใช้สื่อการเรียนการสอนของชั้นเรียนลิงก์

รูปที่ 1 มุมมองของครูเกี่ยวกับงานใน CourseWork ฉบับร่างที่มี "เนื้อหาลิงก์"

ผู้ใช้ที่มีสิทธิ์

ทำดังต่อไปนี้ถ้าผู้ใช้สามารถสร้างไฟล์แนบของส่วนเสริม

  1. สร้างงาน CourseWork ใหม่โดยไม่มีไฟล์แนบ
  2. สร้างไฟล์แนบของส่วนเสริม

Python

if is_create_attachment_eligible:
  coursework = {
    'title': 'My CourseWork Assignment with Add-on Attachment',
    'description': 'Created using the Classroom CourseWork API.',
    'workType': 'ASSIGNMENT',
    'state': 'DRAFT',  # Set to 'PUBLISHED' to assign to students.
    'maxPoints': 100,
  }

  assignment = (
    classroom_service.courses()
    .courseWork()
    .create(courseId=course_id, body=coursework)
    .execute()
  )

  print(
    f'Empty assignment created with ID: {assignment.get("id")}'
  )

  attachment = {
    'teacherViewUri': {'uri': teacher_view_url},
    'studentViewUri': {'uri': student_view_url},
    'studentWorkReviewUri': {'uri': grade_student_work_url},
    'title': f'Test Attachment {test_label}',
  }

  add_on_attachment = (
    service.courses()
    .courseWork()
    .addOnAttachments()
    .create(
      courseId=course_id,
      itemId=assignment.get("id"),  # ID of the new assignment.
      body=attachment,
    )
    .execute()
  )

  print(
    f'Add-on attachment created with ID: {add_on_attachment.get("id")}'
  )

ส่วนเสริมจะปรากฏเป็นการ์ดไฟล์แนบใน Classroom URL ที่ระบุในคำขอเปิดใน iframe สำหรับแต่ละมุมมอง