קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
במדריך הזה מוסבר איך ליצור קבצים מצורפים לתוספים באתר או באפליקציה.
האינטראקציות דומות ליצירת מטלות באמצעות נקודות הקצה של CourseWork API. כדי לאפשר למשתמשים ליצור קבצים מצורפים לתוספים מהאתר או מהאפליקציה שלכם, צריך להטמיע את תהליך המעבר הזה.
תהליך עבודה
באופן כללי, תהליך יצירת הקובץ המצורף מתבצע לפי הרצף הבא:
משתמש שהוא מורה פותח את האתר או האפליקציה שלכם. הוא בוחר פריט תוכן כדי להקצות אותו לתלמידים.
אם המשתמש לא יכול ליצור קבצים מצורפים לתוספים, צריך ליצור מטלה בכלי המטלות עם כתובת ה-URL לתוכן שנבחר כחומר קישור.
אם המשתמש יכול ליצור קבצים מצורפים של תוספים, צריך לבצע את הפעולות הבאות:
יוצרים מטלה.
יוצרים קובץ מצורף של תוסף שמקשר לתוכן שנבחר ומשייכים אותו למטלה החדשה.
מודיעים למורה שהמטלה נוצרה בהצלחה.
כל פעולה מתוארת בקטעים הבאים.
בדיקה אם משתמש יכול ליצור קבצים מצורפים של תוספים
אתם יכולים ליצור קבצים מצורפים לתוספים בשם משתמש שעומד בדרישות. משתמש שעומד בדרישות הוא משתמש שהוא מורה בקורס שבו מנסים ליצור מטלות ב'כלי המטלות' וגם יש לו רישיון למהדורת Teaching & Learning או Education Plus של Google Workspace for Education.
קודם צריך לקבוע אם המשתמש יכול ליצור קבצים מצורפים של תוספים. כדי לעשות זאת, צריך לשלוח בקשה לנקודת הקצה 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
ifnotis_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 בלי קבצים מצורפים.
יוצרים קובץ מצורף של תוסף.
מגדירים את itemId של AddOnAttachment לערך id של ההקצאה החדשה שנוצרה.
ifis_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")}')
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-29 (שעון UTC)."],[],[],null,["# Create attachments outside of Google Classroom\n\nThis guide addresses creating add-on attachments in your website or application.\nThe interactions are similar to [creating assignments using the CourseWork API\nendpoints](/workspace/classroom/guides/manage-coursework#create_assignments). Implement this journey to allow users to create add-on attachments\nfrom your website or application.\n| **Important:** We strongly recommend implementing this attachment creation flow if you already create [`CourseWork`](/workspace/classroom/reference/rest/v1/courses.courseWork) assignments. Extending a CourseWork implementation lets you convert many more users to your add-on and requires little additional work.\n\nWorkflow\n--------\n\nAt a high level, the attachment creation journey follows this sequence:\n\n1. A teacher user opens your website or app. They select a piece of content to assign to their students.\n2. [Check that the user can create add-on attachments](#check-whether).\n3. If the user **can't** create add-on attachments, create a CourseWork assignment with the URL to the selected content as a Link Material.\n4. If the user **can** create add-on attachments, do the following:\n 1. Create an assignment.\n 2. Create an add-on attachment that links to the selected content and associate it with the new assignment.\n5. Inform the teacher that the assignment has been created successfully.\n\nEach action is described in the following sections.\n\nCheck whether a user can create add-on attachments\n--------------------------------------------------\n\nYou can create add-on attachments on behalf of an eligible user. An eligible\nuser is a user who is a teacher in the course you are trying to create\nCourseWork assignments in **and** has the Teaching \\& Learning or Education Plus\nGoogle Workspace for Education edition license assigned to them.\n| **Key Point:** Eligibility to create add-on attachments may be different for each user and can change over time. Always check the user's eligibility before attempting to create add-on attachments.\n| **Important:** Eligibility checks using the Classroom API are in public preview and available in preview version `V1_20240930_PREVIEW` and later. To use API methods in public preview, you must be part of the [Google Workspace Developer Preview Program](/workspace/preview) and [perform additional setup](/workspace/classroom/reference/preview) beyond typical Classroom API usage.\n\nBegin by determining whether the user can create add-on attachments. You can do\nso by issuing a request to the [`userProfiles.checkUserCapability`](/workspace/classroom/reference/rest/v1/userProfiles/checkUserCapability) endpoint\nwith the `CREATE_ADD_ON_ATTACHMENT` capability parameter. Inspect the boolean\n`allowed` field in the response; a `true` value indicates that the user is\neligible to create add-on attachments.\n**Warning:** Requests to create add-on attachments for users with the `CREATE_ADD_ON_ATTACHMENT` capability are not guaranteed to succeed. For example, a user with the capability will receive a `403` response error if you attempt to create add-on attachments on their behalf in a course in which the user is not a teacher. \n\n### Python\n\n eligibility_response = (\n classroom_service.userProfiles()\n .checkUserCapability(\n userId=\"me\",\n capability=\"CREATE_ADD_ON_ATTACHMENT\",\n # The previewVersion is necessary while the method is available in the\n # Workspace Developer Preview Program.\n previewVersion=\"V1_20240930_PREVIEW\",\n ).execute()\n )\n is_create_attachment_eligible = (\n eligibility_response.get('allowed')\n )\n print('User eligibility for add-on attachment creation: '\n f'{is_create_attachment_eligible}.')\n\nRoute the user based on their eligibility\n-----------------------------------------\n\nEligibility determines whether you can create add-on attachments for a user.\n| **Important:** Add-ons offer significant user experience advantages. Always create add-on attachments for eligible users.\n\n### Ineligible user\n\nIf the user *can't* create add-on attachments, then create a new [`CourseWork`](/workspace/classroom/reference/rest/v1/courses.courseWork)\nassignment with the user-selected content URL as a [`Link`](/workspace/classroom/reference/rest/v1/Material). \n\n### Python\n\n if not is_create_attachment_eligible:\n coursework = {\n 'title': 'My CourseWork Assignment with Link Material',\n 'description': 'Created using the Classroom CourseWork API.',\n 'workType': 'ASSIGNMENT',\n 'state': 'DRAFT', # Set to 'PUBLISHED' to assign to students.\n 'maxPoints': 100,\n 'materials': [\n {'link': {'url': my_content_url}}\n ]\n }\n\n assignment = (\n service.courses()\n .courseWork()\n .create(courseId=course_id, body=coursework)\n .execute()\n )\n\n print(\n f'Link Material assignment created with ID: {assignment.get(\"id\")}'\n )\n\nThe response contains an assignment in the requested course with the content\nattached. Users can click the `Link` to open the content in your site in a new\ntab.\n\n**Figure 1.** Teacher view of a draft CourseWork assignment with Link Material.\n\n### Eligible user\n\nDo the following if the user *can* create add-on attachments.\n\n1. Create a new `CourseWork` assignment without any attachments.\n2. Create an add-on attachment.\n - Set the[`AddOnAttachment`](/workspace/classroom/reference/rest/v1/courses.courseWork.addOnAttachments#resource:-addonattachment)'s `itemId` to the `id` of the newly created assignment.\n - Ensure that you provide URLs to the user-selected content for [each View\n that you support](/workspace/classroom/add-ons/get-started/iframes/iframes-overview).\n\n### Python\n\n if is_create_attachment_eligible:\n coursework = {\n 'title': 'My CourseWork Assignment with Add-on Attachment',\n 'description': 'Created using the Classroom CourseWork API.',\n 'workType': 'ASSIGNMENT',\n 'state': 'DRAFT', # Set to 'PUBLISHED' to assign to students.\n 'maxPoints': 100,\n }\n\n assignment = (\n classroom_service.courses()\n .courseWork()\n .create(courseId=course_id, body=coursework)\n .execute()\n )\n\n print(\n f'Empty assignment created with ID: {assignment.get(\"id\")}'\n )\n\n attachment = {\n 'teacherViewUri': {'uri': teacher_view_url},\n 'studentViewUri': {'uri': student_view_url},\n 'studentWorkReviewUri': {'uri': grade_student_work_url},\n 'title': f'Test Attachment {test_label}',\n }\n\n add_on_attachment = (\n service.courses()\n .courseWork()\n .addOnAttachments()\n .create(\n courseId=course_id,\n itemId=assignment.get(\"id\"), # ID of the new assignment.\n body=attachment,\n )\n .execute()\n )\n\n print(\n f'Add-on attachment created with ID: {add_on_attachment.get(\"id\")}'\n )\n\n| **Note:** An add-on token is not required if creating an attachment on an assignment that you created.\n\nThe add-on appears as an [attachment card](/workspace/classroom/add-ons/get-started/attachments-journey) in Classroom. The URLs\nspecified in the request open in the appropriate\n[iframe for each View](/workspace/classroom/add-ons/get-started/iframes/iframes-overview)."]]