Google 클래스룸 외부에서 첨부파일 만들기

이 가이드에서는 웹사이트 또는 애플리케이션에서 부가기능 첨부파일을 만드는 방법을 설명합니다. 상호작용은 CourseWork API 엔드포인트를 사용하여 과제를 만드는 것과 비슷합니다. 사용자가 웹사이트 또는 애플리케이션에서 부가기능 첨부파일을 만들 수 있도록 이 여정을 구현하세요.

워크플로

개략적으로 연결 생성 과정은 다음 순서를 따릅니다.

  1. 교사 사용자가 웹사이트 또는 앱을 열고 학생들에게 할당할 콘텐츠를 선택합니다.
  2. 사용자가 부가기능 첨부파일을 만들 수 있는지 확인하기
  3. 사용자가 부가기능 첨부파일을 만들 수 없는 경우 선택한 콘텐츠의 URL을 링크 자료로 사용하여 CourseWork 과제를 만듭니다.
  4. 사용자가 부가기능 첨부파일을 만들 수 있는 경우 다음 안내를 따르세요.
    1. 과제를 만듭니다.
    2. 선택한 콘텐츠에 연결되는 부가기능 첨부파일을 만들어 새 과제와 연결합니다.
    3. 과제가 생성되었다고 선생님에게 알립니다.

각 작업은 다음 섹션에서 설명합니다.

사용자가 부가기능 첨부파일을 만들 수 있는지 확인하기

자격 요건을 충족하는 사용자를 대신하여 부가기능 첨부파일을 만들 수 있습니다. 자격 요건을 충족하는 사용자는 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를 클릭하여 새 탭에서 사이트의 콘텐츠를 열 수 있습니다.

Link 자료를 사용한 CourseWork 과제 초안

그림 1. Link 자료가 포함된 CourseWork 과제 초안의 교사 화면

대상 사용자

사용자가 부가기능 첨부파일을 만들 수 있는 경우 다음 단계를 따르세요.

  1. 첨부파일 없이 새 CourseWork 과제를 만듭니다.
  2. 부가기능 첨부파일을 만듭니다.
    • AddOnAttachmentpostId를 새로 만든 할당의 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에서 열립니다.