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

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

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

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

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

असाइनमेंट मैनेजमेंट के लिए 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 Classroom के असाइनमेंट और अटैचमेंट बना सकते हैं. असल में, यह आपकी मौजूदा वेबसाइट या ऐप्लिकेशन हो सकता है. उदाहरण के लिए, किसी बाहरी साइट के तौर पर काम करने के लिए, आपको एक मॉक वेब पेज बनाना होगा. आपको एक ऐसे बटन या लिंक की ज़रूरत होगी जिस पर क्लिक करने से नया रूट खुलता है. यह नया असाइनमेंट बनाने के लिए, सुझाए गए 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. Google Classroom में बिना अटैचमेंट वाला courseWork असाइनमेंट बनाने के लिए, एपीआई अनुरोध भेजें.
  2. नए असाइनमेंट का id एक्सट्रैक्ट करें.
  3. नया कोर्सवर्क AddOnAttachment बनाएं.
  4. Google Classroom में बनाए गए नए असाइनमेंट पर, ऐड-ऑन अटैचमेंट बनाने का अनुरोध भेजें.

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_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 और courseWork संसाधनों के get और list तरीकों से अनुरोध करके, ये आइडेंटिफ़ायर मिल सकते हैं. ये courseWork असाइनमेंट बनाने पर जवाब में भी दिखते हैं.

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

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

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

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

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

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