बाहरी अटैचमेंट और चालू करें

Classroom ऐड-ऑन के लिए सिलसिलेवार तरीके से निर्देश देने वाला यह सातवां चरण है सिलसिलेवार तरीके से निर्देश देने वाली सीरीज़ देखें.

सिलसिलेवार तरीके से दिए गए इस निर्देश में, ऐड-ऑन बनाने के लिए, वेब ऐप्लिकेशन में व्यवहार जोड़ा गया है Google Classroom के बाहर के अटैचमेंट. इस व्यवहार का इस्तेमाल करके उपयोगकर्ता आपके मौजूदा प्रॉडक्ट या वेबसाइट से ऐड-ऑन अटैचमेंट बनाते हैं. यह है CourseWork इंटिग्रेशन में भी एक शानदार योगदान है, क्योंकि आप मौजूदा ग्राहकों को आपके ऐड-ऑन के इस्तेमाल से मिलने वाले बेहतर उपयोगकर्ता अनुभव में कोई बदलाव नहीं करेगा मदद कर सकता है. सुझाई गई प्रोसेस के बारे में, अटैचमेंट बनाएं Classroom के बाहर गाइड पेज पर जाएं.

ऐड-ऑन से किसी असाइनमेंट में बदलाव करने के लिए, अपने ऐड-ऑन में व्यवहार भी जोड़ा जाता है अटैचमेंट को प्रोग्राम के हिसाब से. आप ऐसे किसी भी असाइनमेंट में बदलाव कर सकते हैं, जिसमें आपके ऐड-ऑन अटैचमेंट मौजूद हैं. इससे कोई फ़र्क़ नहीं पड़ता कि उन्हें किसने बनाया है. यह है विशेष रूप से तब उपयोगी होता है, जब छात्र/छात्रा ने असाइनमेंट पूरा कर लिया हो गतिविधि के दौरान, शिक्षक को यह संकेत दिया जाता है कि असाइन किए गए टास्क पूरे हो गए हैं और छात्र/छात्रा का काम समीक्षा के लिए तैयार है.

content-type के साथ काम करने वाले ऐड-ऑन के फ़ाइनल वर्शन को बढ़ाया जा सकता है या गतिविधि टाइप के अटैचमेंट. इस गाइड में कॉन्टेंट टाइप वाले अटैचमेंट का इस्तेमाल किया गया है.

असाइनमेंट मैनेजमेंट के लिए OAuth का स्कोप जोड़ें

पक्का करें कि आपका ऐप्लिकेशन इन दायरों के लिए अनुरोध करता हो:

  • https://www.googleapis.com/auth/classroom.addons.teacher
  • https://www.googleapis.com/auth/classroom.addons.student
  • https://www.googleapis.com/auth/classroom.coursework.students

classroom.coursework.students स्कोप की पहले ज़रूरत नहीं थी और अब इसका इस्तेमाल CourseWork असाइनमेंट बनाने या उनमें बदलाव करने के लिए किया जाता है. इस दायरे को सूचियों में जोड़ें आपके Cloud प्रोजेक्ट Google Workspace Marketplace SDK टूल, OAuth की सहमति वाली स्क्रीन, और आपके सर्वर कोड.

Python

  SCOPES = [
    "https://www.googleapis.com/auth/classroom.addons.teacher",
    "https://www.googleapis.com/auth/classroom.addons.student",
    "https://www.googleapis.com/auth/classroom.coursework.students",
  ]

Classroom में असाइनमेंट बनाना

बिना iframe वाले वेब पेज पर बटन जोड़ना

सिलसिलेवार तरीके से दिए गए निर्देशों में बताए गए फ़्लो की मदद से, उपयोगकर्ता Google Classroom में मौजूद ऐसे असाइनमेंट और अटैचमेंट जो Google के नहीं हैं. तय सीमा में तो शायद यह आपकी मौजूदा वेबसाइट या ऐप्लिकेशन है. इस उदाहरण के लिए, किसी बाहरी साइट के रूप में काम करने के लिए, आपको एक मॉक वेब पेज बनाना होगा. बटन होना ज़रूरी है या लिंक होता है, जिस पर क्लिक करने से नया रूट खुलता है, जो सुझाया गया नया असाइनमेंट बनाने के लिए, CourseWork फ़्लो पर जाएं.

उपयोगकर्ता को साइन इन करने की अनुमति देने के लिए, आपको कोई बटन या लिंक भी जोड़ना होगा. पास पहले से नहीं है. बाद की प्रोसेस पूरी करने के लिए, आपको उपयोगकर्ता क्रेडेंशियल की ज़रूरत होगी एपीआई अनुरोध सबमिट करते हैं, इसलिए उन्हें OAuth 2.0 हैंडशेक पूरा करना होगा. साइन-इन देखें सिलसिलेवार तरीके से निर्देश पढ़ें.

Python

Python का दिया गया उदाहरण, लागू किए गए /index रूट में बदलाव करता है के लिए, सिलसिलेवार तरीके से निर्देश देने वाले पहले चरण में दिए गए निर्देशों का पालन करें.

<!-- /webapp/templates/index.html -->
<a href="clear-credentials.html">Logout</a>
<a href="start-auth-flow.html">Login</a>

<br>

<a href="create-coursework-assignment.html">Create a CourseWork Assignment</a>

अपनी वेबसाइट में डेस्टिनेशन दिखाने के लिए, एचटीएमएल टेंप्लेट जोड़ें. यह पेज उस कॉन्टेंट को दिखाएगा जिसे आपके CourseWork से अटैच किया जाएगा असाइनमेंट शामिल करें.

<!-- /webapp/templates/example-coursework-assignment.html -->
<h1>CourseWork assignment loaded!</h1>
<p>You've loaded a CourseWork assignment! It was created from an external web page.</p>

courseWork से जुड़े रूट मैनेज करने के लिए, एक नई Python मॉड्यूल फ़ाइल बनाएं. हमारे दिए गए उदाहरण में यह coursework_routes.py है. इन्हें जोड़ें तीन रास्ते; ध्यान रखें कि आपको कुछ कॉन्टेंट बाद में भरना होगा.

# /webapp/coursework_routes.py
@app.route("/create-coursework-assignment")
def create_coursework_assignment():
  """
  Completes the assignment creation flow.
  """

  # Check that the user is signed in. If not, perform the OAuth 2.0
  # authorization flow.
  credentials = get_credentials()

  if not credentials:
    return start_auth_flow("coursework_assignment_callback")

  # Construct the Google Classroom service.
  classroom_service = get_classroom_service()

  pass  # To be completed later.

@app.route("/example-coursework-assignment/<assignment_type>")
def example_coursework_assignment(assignment_type):
  """
  Renders the "example-coursework-assignment.html" template.
  """
  return flask.render_template(
      "example-coursework-assignment.html", assignment_type=assignment_type
  )

@app.route("/coursework-assignment-callback")
def coursework_assignment_callback():
  """
  Completes the OAuth 2.0 handshake and stores credentials in the session.
  This is identical to the callback introduced in the sign-in walkthrough,
  but redirects the user to the index page instead of the attachment
  discovery page.
  """
  flow = google_auth_oauthlib.flow.Flow.from_client_secrets_file(
      CLIENT_SECRETS_FILE,
      scopes=SCOPES,
      state=flask.session["state"],
      redirect_uri=flask.url_for("coursework_assignment_callback", _external=True),
  )

  flow.fetch_token(authorization_response=flask.request.url)

  credentials = flow.credentials
  flask.session["credentials"] = session_credentials_to_dict(
      credentials
  )

  # Close the current window and redirect the user to the index page.
  return flask.render_template("close-me.html", redirect_destination="index")

यह देखना कि उपयोगकर्ता ने ऐड-ऑन बनाया है या नहीं

आपके पास कॉन्टेंट बनाने से पहले, उपयोगकर्ता को कई ज़रूरी शर्तें पूरी करनी होंगी उनकी ओर से ऐड-ऑन अटैचमेंट. सुविधा के लिए, Google यह पता लगाने के लिए courses.checkAddOnCreationEligibility तरीका कि कोई उपयोगकर्ता वह इन शर्तों को पूरा करता है. आवश्यकताएं पूरी करने वाले उपयोगकर्ता को ज़रूरी शर्तें पूरी करने वाला उपयोगकर्ता हो.

CourseWork बनाने के रूट को लागू करने के लिए, ज़रूरी शर्तों की जांच करने की सुविधा जोड़ें. इसके बाद, रिस्पॉन्स में isCreateAttachmentEligible फ़ील्ड की जांच करें. मंज़ूरी पा चुके लोगों के लिए ऐड-ऑन के साथ असाइनमेंट बनाने के लिए लॉजिक का पालन करें अटैचमेंट. अगर ऐसा नहीं है, तो लिंक करें सामग्री. आपको यहां दिए गए कोर्स का आईडी पता होना चाहिए जिसे उपयोगकर्ता असाइनमेंट बनाना चाहता है. आम तौर पर, सभी उपयोगकर्ताओं को चुनें कि कौनसा कोर्स इस्तेमाल करना है. सरलता के लिए, हम हार्ड-कोड किए गए मान का यह उदाहरण.

Python

# /webapp/coursework_routes.py
@app.route("/create-coursework-assignment")
def create_coursework_assignment():
  """
  Completes the assignment creation flow.
  """
  # ... Check that the user is signed in and get the Classroom service ...

  # The ID of the course to which the assignment will be added.
  course_id = 1234567890  # TODO(developer) Replace with an actual course ID.

  # Check whether the user can create add-on attachments.
  eligibility_response = (
      classroom_service.courses()
      .checkAddOnCreationEligibility(courseId=course_id)
      .execute()
  )
  is_create_attachment_eligible = eligibility_response.get("isCreateAttachmentEligible")

  if is_create_attachment_eligible:
    # See the "Create an assignment with add-on attachment for eligible users" section for implementation.
  if not is_create_attachment_eligible:
    # See the "Create a Link Material" section for implementation.

ज़रूरी शर्तें पूरी करने वाले उपयोगकर्ताओं के लिए, ऐड-ऑन अटैचमेंट वाला असाइनमेंट बनाएं

अगर उपयोगकर्ता ऐड-ऑन अटैचमेंट बनाने की ज़रूरी शर्तें पूरी करता है, तो ये काम करें:

  1. courseWork असाइनमेंट बनाने के लिए, एपीआई अनुरोध भेजें Google Classroom के साथ कोई अटैचमेंट नहीं होना चाहिए.
  2. नए असाइनमेंट का id एक्सट्रैक्ट करें.
  3. नया कोर्सवर्क AddOnAttachment बनाएं.
  4. नए बनाए गए पेज पर ऐड-ऑन अटैचमेंट बनाने का अनुरोध भेजें असाइनमेंट करने में मदद मिलती है.

Python

# /webapp/coursework_routes.py
if is_create_attachment_eligible:
  # Create an assignment.
  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.
  }

  # Issue a request to create the assignment.
  create_assignment_response = (
      classroom_service.courses()
      .courseWork()
      .create(courseId=course_id, body=coursework)
      .execute()
  )

  # Create an add-on attachment that links to the selected content and
  # associate it with the new assignment.
  content_url = flask.url_for(
      "example_coursework_assignment",
      assignment_type="add-on-attachment",
      _scheme="https",
      _external=True,
  )

  # Construct an AddOnAttachment instance.
  attachment = {
      "teacherViewUri": {"uri": content_url},
      "studentViewUri": {"uri": content_url},
      "title": f'Test Attachment for Assignment {create_assignment_response.get("id")}',
  }

  # Issue a request to create the attachment.
  add_on_attachment_response = (
      classroom_service.courses()
      .courseWork()
      .addOnAttachments()
      .create(
          courseId=course_id,
          itemId=create_assignment_response.get("id"),  # ID of the new assignment.
          body=attachment,
      )
      .execute()
  )

अगर उपयोगकर्ता ऐड-ऑन अटैचमेंट बनाने की ज़रूरी शर्तें पूरी नहीं करता, तो लिंक बनाएं इसके बजाय, नीचे दिए गए काम करें:

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.
        # Specify the URL for your content as a Link Material.
        "materials": [
            {
                "link": {
                    "url": flask.url_for(
                        "example_coursework_assignment",
                        assignment_type="link-material",
                        _scheme="https",
                        _external=True,
                    )
                }
            }
        ],
    }

    # Issue a request to create the assignment.
    assignment_response = (
        classroom_service.courses()
        .courseWork()
        .create(courseId=course_id, body=coursework)
        .execute()
    )

पहले से बने असाइनमेंट में बदलाव करें

Google Classroom को ऐक्सेस किया जा सकता है, उसमें बदलाव किया जा सकता है, उसे चालू किया जा सकता है, उस पर फिर से दावा किया जा सकता है या उसे वापस किया जा सकता है ऐसी स्ट्रीम आइटम जिसमें कम से कम एक ऐड-ऑन अटैचमेंट हो. इससे कोई फ़र्क़ नहीं पड़ता कि कौन स्ट्रीम आइटम बनाया. स्ट्रीम आइटम कोई भी Announcement, CourseWork हैं असाइनमेंट या CourseWorkMaterial.

इसे दिखाने के लिए, आपको दिए गए स्ट्रीम आइटम में बदलाव करने के लिए एक रूट जोड़ना होगा. इसका इस्तेमाल करें का इस्तेमाल करके, यह पुष्टि की जा सकती है कि आपके बनाए गए स्ट्रीम आइटम को ऐक्सेस और उनमें बदलाव किया जा सकता है एपीआई का इस्तेमाल करके और शिक्षक ने Google Classroom के यूज़र इंटरफ़ेस (यूआई) से बनाया.

उस वेब पेज में एक और लिंक या बटन जोड़ें जिसमें आपने पहली बार बदलाव किया था सिलसिलेवार तरीके से निर्देश पढ़ें. CourseWork में बदलाव करने के लिए, यह एक नया रूट खोलेगा असाइनमेंट शामिल करें.

Python

Python का दिया गया उदाहरण, उस /index रूट में बदलाव करता है जिसमें बदलाव किया गया था इन सिलसिलेवार निर्देशों में बताए गए पहले से ही बताया गया है.

<!-- /webapp/templates/index.html -->
<a href="modify-coursework-assignment.html">Create a CourseWork Assignment</a>

courseWork से जुड़े रूट मैनेज करने के लिए, कोई नया रूट बनाएं. यह इवेंट हमारे दिए गए उदाहरण में coursework_routes.py फ़ाइल है.

# Check that the user is signed in.
credentials = get_credentials()

if not credentials:
  return start_auth_flow("coursework_assignment_callback")

# Get the Google Classroom service.
classroom_service = get_classroom_service()

# The ID of the course to which the assignment will be added.
# Ordinarily, you'll prompt the user to specify which course to use. For
# simplicity, we use a hard-coded value in this example.
course_id = 1234567890  # TODO(developer) Replace with an actual course ID.
assignment_id = 1234567890  # TODO(developer) Replace with an actual assignment ID.

# Retrieve details about the CourseWork assignment.
get_coursework_response = (
    classroom_service.courses()
    .courseWork()
    .get(courseId=course_id, id=assignment_id)
    .execute()
)

# Alter the current title.
assignment_title = f"{get_coursework_response.get('title')} (Modified by API request)"

# Issue a request to modify the assignment.
modify_coursework_response = (
    classroom_service.courses()
    .courseWork()
    .patch(
        courseId=course_id,
        id=assignment_id,
        updateMask="title",
        body={"title": assignment_title},
    )
    .execute()
)

ऐड-ऑन का परीक्षण करें

चीज़ों को आसान रखने के लिए, दिए गए उदाहरणों में हार्ड कोड किए गए कोर्स और असाइनमेंट आइडेंटिफ़ायर. इनसे अनुरोध करके, ये आइडेंटिफ़ायर पाए जा सकते हैं courses में बताए गए get और list तरीकों के लिए शिक्षक के क्रेडेंशियल courseWork संसाधन. इन्हें रिपोर्ट बनाते समय जवाब में भी लौटाया जाता है courseWork असाइनमेंट.

अपना सर्वर चलाएं, फिर अपने इंडेक्स पेज पर जाएं और शिक्षक के तौर पर साइन इन करें बिना Google Workspace for Education के Teaching & Learning या Plus का लाइसेंस. आप चाहें, तो टेस्ट डोमेन के लाइसेंस की स्थिति से Admin console.कोर्सवर्क असाइनमेंट बनाएं पर क्लिक करें बटन पर क्लिक करें, फिर Google Classroom का यूज़र इंटरफ़ेस (यूआई) खोलें और पुष्टि करें कि एक असाइनमेंट लिंक मटीरियल अटैचमेंट बनाया गया. अटैचमेंट में इसका टाइटल दिखना चाहिए लिंक किए गए वेब पेज और यूआरएल को,

ऐड-ऑन अटैचमेंट बनाने की जांच करें

इंडेक्स पेज पर वापस जाएं और Google Workspace for Education Teaching से शिक्षक के तौर पर साइन इन करें &amp; Learning या Plus का लाइसेंस. कोर्सवर्क असाइनमेंट बनाएं पर क्लिक करें बटन पर क्लिक करें, फिर Google Classroom का यूज़र इंटरफ़ेस (यूआई) खोलें और पुष्टि करें कि एक असाइनमेंट एक ऐड-ऑन अटैचमेंट बनाया गया. अटैचमेंट में आपकी ऐड-ऑन ऐप्लिकेशन और आपके कोड में दर्ज शीर्षक.

असाइनमेंट में बदलाव की जांच करें

इंडेक्स पेज पर वापस जाएं और पक्का करें कि आपने शिक्षक के तौर पर साइन इन किया है के साथ-साथ Learning या Plus का लाइसेंस. कोर्सवर्क में बदलाव करें पर क्लिक करें असाइनमेंट बटन पर क्लिक करें. इसके बाद, Google Classroom के यूज़र इंटरफ़ेस (यूआई) पर वापस जाएं और पुष्टि करें कि असाइनमेंट का टाइटल बदल दिया गया है.

बधाई हो! आपने सिलसिलेवार तरीके से निर्देश देने वाली सीरीज़ पूरी कर ली है.