이 가이드에서는 웹사이트 또는 애플리케이션에서 부가기능 첨부파일을 만드는 방법을 알아봅니다. 상호작용은 CourseWork API 엔드포인트를 사용하여 할당 만들기와 유사합니다. 사용자가 웹사이트 또는 애플리케이션에서 부가기능 첨부파일을 만들 수 있도록 이 여정을 구현하세요.
워크플로
연결 생성 과정은 개략적으로 다음 순서를 따릅니다.
- 교사 사용자가 웹사이트 또는 앱을 열고 학생에게 할당할 콘텐츠를 선택합니다.
- 사용자가 부가기능 첨부파일을 만들 수 있는지 확인합니다.
- 사용자가 부가기능 첨부파일을 만들 수 없는 경우 선택한 콘텐츠의 URL을 링크 자료로 사용하여 CourseWork 할당을 만듭니다.
- 사용자가 부가기능 첨부파일을 만들 수 있는 경우 다음을 수행합니다.
- 과제를 만듭니다.
- 선택한 콘텐츠에 연결되는 부가기능 첨부파일을 만들어 새 과제와 연결합니다.
- 과제가 생성되었다고 교사에게 알립니다.
각 작업은 다음 섹션에서 설명합니다.
사용자가 부가기능 첨부파일을 만들 수 있는지 확인하기
자격 요건을 충족하는 사용자를 대신하여 부가기능 첨부파일을 만들 수 있습니다. 자격 요건을 충족하는 사용자는 CourseWork 과제를 만들려는 과정의 교사이고, 또한 Teaching & Learning 또는 Education Plus Google Workspace for Education 버전 라이선스가 할당된 사용자입니다.
먼저 사용자가 지정된 Course
에서 부가기능을 만들 수 있는지 확인합니다.
과정 ID를 포함하여 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}.')
사용자가 자격을 충족하면 응답에 true
로 설정된 불리언 isCreateAttachmentEligible
값이 포함됩니다. 사용자가 자격요건을 충족하지 않으면 응답은 isCreateAttachmentEligible
불리언을 반환하지 않습니다.
자격 요건에 따라 사용자 전달
자격 요건에 따라 사용자의 부가기능 첨부파일을 만들 수 있는지 여부가 결정됩니다.
부적격 사용자
사용자가 부가기능 첨부파일을 만들 수 없는 경우 사용자가 선택한 콘텐츠 URL을 Link
로 사용하여 새 CourseWork
할당을 만듭니다.
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")}'
)
부가기능은 클래스룸에서 첨부파일 카드로 표시됩니다. 요청에 지정된 URL은 각 뷰의 적절한 iframe에서 열립니다.