คู่มือนี้จะกล่าวถึงการสร้างไฟล์แนบของส่วนเสริมในเว็บไซต์หรือแอปพลิเคชัน การโต้ตอบจะคล้ายกับการสร้างงานโดยใช้ปลายทาง CourseWork API ใช้เส้นทางนี้เพื่อให้ผู้ใช้สร้างไฟล์แนบของส่วนเสริม จากเว็บไซต์หรือแอปพลิเคชันของคุณได้
ขั้นตอนการทำงาน
ในระดับสูง เส้นทางการสร้างไฟล์แนบจะเป็นไปตามลำดับต่อไปนี้
- ผู้ใช้ที่เป็นครูเปิดเว็บไซต์หรือแอปของคุณ แล้วเลือกเนื้อหาเพื่อ มอบหมายให้นักเรียน
- ตรวจสอบว่าผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้
- หากผู้ใช้สร้างไฟล์แนบของส่วนเสริมไม่ได้ ให้สร้างงาน CourseWork โดยใช้ URL ของเนื้อหาที่เลือกเป็นสื่อการเรียนรู้แบบลิงก์
- หากผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้ ให้ทำดังนี้
- สร้างงาน
- สร้างไฟล์แนบส่วนเสริมที่ลิงก์ไปยังเนื้อหาที่เลือกและ เชื่อมโยงกับงานใหม่
- แจ้งให้ครูทราบว่าสร้างงานเรียบร้อยแล้ว
เราจะอธิบายการดำเนินการแต่ละอย่างในส่วนต่อไปนี้
ตรวจสอบว่าผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้หรือไม่
คุณสร้างไฟล์แนบของส่วนเสริมในนามของผู้ใช้ที่มีสิทธิ์ได้ ผู้ใช้ที่มีสิทธิ์ คือผู้ใช้ที่เป็นครูในหลักสูตรที่คุณพยายามสร้าง งานใน CourseWork และมีใบอนุญาต Google Workspace for Education รุ่น Teaching & Learning หรือ Education Plus ที่กำหนดให้
เริ่มต้นด้วยการพิจารณาว่าผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้หรือไม่ คุณทำได้โดยส่งคำขอไปยังปลายทาง userProfiles.checkUserCapability
พร้อมพารามิเตอร์ความสามารถ CREATE_ADD_ON_ATTACHMENT
ตรวจสอบฟิลด์บูลีน
allowed
ในการตอบกลับ ค่า true
แสดงว่าผู้ใช้มีสิทธิ์
สร้างไฟล์แนบของส่วนเสริม
Python
eligibility_response = (
classroom_service.userProfiles()
.checkUserCapability(
userId="me",
capability="CREATE_ADD_ON_ATTACHMENT",
# The previewVersion is necessary while the method is available in the
# Workspace Developer Preview Program.
previewVersion="V1_20240930_PREVIEW",
).execute()
)
is_create_attachment_eligible = (
eligibility_response.get('allowed')
)
print('User eligibility for add-on attachment creation: '
f'{is_create_attachment_eligible}.')
กำหนดเส้นทางให้ผู้ใช้ตามการมีสิทธิ์
การมีสิทธิ์จะกำหนดว่าคุณจะสร้างไฟล์แนบของส่วนเสริมสำหรับผู้ใช้ได้หรือไม่
ผู้ใช้ที่ไม่มีสิทธิ์
หากผู้ใช้สร้างไฟล์แนบส่วนเสริมไม่ได้ ให้สร้าง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
เพื่อเปิดเนื้อหาในเว็บไซต์ของคุณในแท็บใหม่
รูปที่ 1 มุมมองของครูในงาน CourseWork ฉบับร่างที่มีสื่อการเรียนการสอนแบบลิงก์
ผู้ใช้ที่มีสิทธิ์
ทำดังนี้หากผู้ใช้สร้างไฟล์แนบของส่วนเสริมได้
- สร้างงาน
CourseWork
ใหม่โดยไม่มีไฟล์แนบ - สร้างไฟล์แนบของส่วนเสริม
- ตั้งค่า
AddOnAttachment
ของitemId
เป็นid
ของงานที่สร้างขึ้นใหม่ - ตรวจสอบว่าคุณได้ระบุ URL ของเนื้อหาที่ผู้ใช้เลือกสำหรับแต่ละมุมมอง ที่คุณรองรับ
- ตั้งค่า
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 ที่เหมาะสมสำหรับแต่ละมุมมอง