একটি ফর্ম বা কুইজ তৈরি করুন

এই পৃষ্ঠায় ফর্মগুলির সাথে সম্পর্কিত এই কাজগুলি কীভাবে সম্পাদন করতে হয় তা বর্ণনা করা হয়েছে:

  • একটি নতুন ফর্ম তৈরি করুন
  • একটি বিদ্যমান ফর্মের ডুপ্লিকেট তৈরি করুন
  • একটি ফর্মকে কুইজে রূপান্তর করুন

শুরু করার আগে

এই পৃষ্ঠার কাজগুলি শুরু করার আগে নিম্নলিখিত কাজগুলি করুন:

  • আর্লি অ্যাডপটার প্রোগ্রামের নির্দেশাবলীতে অনুমোদন বা প্রমাণীকরণ এবং শংসাপত্র সেটআপ সম্পূর্ণ করুন।
  • ফর্মস এপিআই ওভারভিউ পড়ুন।

একটি নতুন ফর্ম তৈরি করুন

একটি ফর্ম তৈরির প্রাথমিক পর্যায়ে শুধুমাত্র একটি শিরোনাম ক্ষেত্র প্রয়োজন - অনুরোধের অন্য কোনও ক্ষেত্র উপেক্ষা করা হবে। একটি ফর্মের বিষয়বস্তু এবং মেটাডেটা তৈরি করতে বা আপডেট করতে, batchUpdate() পদ্ধতি ব্যবহার করুন। আরও তথ্যের জন্য একটি ফর্ম আপডেট করুন বা কুইজ দেখুন।

বিশ্রাম

শুধুমাত্র একটি শিরোনাম দিয়ে forms.create() পদ্ধতিটি কল করুন।

নমুনা অনুরোধের মূল অংশ

{
  "info": {
      "title": "My new form"
  }
}

পাইথন

ফর্ম/স্নিপেট/create_form.py
from apiclient import discovery
from httplib2 import Http
from oauth2client import client, file, tools

SCOPES = "https://www.googleapis.com/auth/drive"
DISCOVERY_DOC = "https://forms.googleapis.com/$discovery/rest?version=v1"

store = file.Storage("token.json")
creds = None
if not creds or creds.invalid:
  flow = client.flow_from_clientsecrets("client_secrets.json", SCOPES)
  creds = tools.run_flow(flow, store)

form_service = discovery.build(
    "forms",
    "v1",
    http=creds.authorize(Http()),
    discoveryServiceUrl=DISCOVERY_DOC,
    static_discovery=False,
)

form = {
    "info": {
        "title": "My new form",
    },
}
# Prints the details of the sample form
result = form_service.forms().create(body=form).execute()
print(result)

নোড.জেএস

ফর্ম/স্নিপেট/create_form.js
import path from 'node:path';
import {authenticate} from '@google-cloud/local-auth';
import {forms} from '@googleapis/forms';

/**
 * Creates a new form.
 */
async function createForm() {
  // Authenticate with Google and get an authorized client.
  const authClient = await authenticate({
    keyfilePath: path.join(__dirname, 'credentials.json'),
    scopes: 'https://www.googleapis.com/auth/drive',
  });

  // Create a new Forms API client.
  const formsClient = forms({
    version: 'v1',
    auth: authClient,
  });

  // The request body to create a new form.
  const newForm = {
    info: {
      title: 'Creating a new form in Node',
    },
  };

  // Send the request to create the form.
  const result = await formsClient.forms.create({
    requestBody: newForm,
  });

  console.log(result.data);
  return result.data;
}

একটি বিদ্যমান ফর্মের ডুপ্লিকেট তৈরি করুন

কন্টেন্ট পুনঃব্যবহার সহজ করার জন্য আপনি Google Drive API দিয়ে একটি বিদ্যমান ফর্মের ডুপ্লিকেট তৈরি করতে পারেন। আপনি Google Forms URL-এ ফর্ম আইডিটি খুঁজে পেতে পারেন:

https://docs.google.com/forms/d/FORM_ID/edit

বিশ্রাম

আপনি যে ফর্মটি কপি করতে চান তার আইডি দিয়ে Google Drive API এর files.copy() পদ্ধতিতে কল করুন।

পাইথন

ফর্ম/স্নিপেট/ডুপ্লিকেট_ফর্ম.পি
import os.path

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# If modifying these scopes, delete the file token.json.
SCOPES = ["https://www.googleapis.com/auth/drive"]


def main():
  """Shows copy file example in Drive v3 API.
  Prints the name, id and other data of the copied file.
  """
  creds = None
  if os.path.exists("token.json"):
    creds = Credentials.from_authorized_user_file("token.json", SCOPES)
  # If there are no (valid) credentials available, let the user log in.
  if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
      creds.refresh(Request())
    else:
      flow = InstalledAppFlow.from_client_secrets_file(
          "client_secrets.json", SCOPES
      )
      creds = flow.run_local_server(port=0)
    # Save the credentials for the next run
    with open("token.json", "w") as token:
      token.write(creds.to_json())

  service = build("drive", "v3", credentials=creds)

  # Call the Drive v3 API
  origin_file_id = "1ox-6vHFeKpC6mon-tL5ygBC8zpbTnTp76JCZdIg80hA"  # example ID
  copied_file = {"title": "my_copy"}
  results = (
      service.files().copy(fileId=origin_file_id, body=copied_file).execute()
  )
  print(results)


if __name__ == "__main__":
  main()

একটি ফর্মকে কুইজে রূপান্তর করুন

একটি কুইজ তৈরি করতে, প্রথমে "একটি নতুন ফর্ম তৈরি করুন" এ বর্ণিত একটি ফর্ম তৈরি করুন, তারপর ফর্মের সেটিংস আপডেট করুন। আপডেটের জন্য ফর্ম আইডি প্রয়োজন।

বিশ্রাম

isQuiz সেটিংটি true তে সেট করতে একটি বিদ্যমান ফর্মে batch.update() পদ্ধতিটি কল করুন।

নমুনা অনুরোধের মূল অংশ

{
  "requests": [
    {
      "updateSettings": {
        "settings": {
          "quizSettings": {
            "isQuiz": true
          }
        },
        "updateMask": "quizSettings.isQuiz"
      }
    }
  ]
}

পাইথন

ফর্ম/স্নিপেট/convert_form.py
from apiclient import discovery
from httplib2 import Http
from oauth2client import client, file, tools

SCOPES = "https://www.googleapis.com/auth/forms.body"
DISCOVERY_DOC = "https://forms.googleapis.com/$discovery/rest?version=v1"

store = file.Storage("token.json")
creds = None
if not creds or creds.invalid:
  flow = client.flow_from_clientsecrets("client_secrets.json", SCOPES)
  creds = tools.run_flow(flow, store)

form_service = discovery.build(
    "forms",
    "v1",
    http=creds.authorize(Http()),
    discoveryServiceUrl=DISCOVERY_DOC,
    static_discovery=False,
)

form = {
    "info": {
        "title": "My new quiz",
    }
}

# Creates the initial form
result = form_service.forms().create(body=form).execute()

# JSON to convert the form into a quiz
update = {
    "requests": [
        {
            "updateSettings": {
                "settings": {"quizSettings": {"isQuiz": True}},
                "updateMask": "quizSettings.isQuiz",
            }
        }
    ]
}

# Converts the form into a quiz
question_setting = (
    form_service.forms()
    .batchUpdate(formId=result["formId"], body=update)
    .execute()
)

# Print the result to see it's now a quiz
getresult = form_service.forms().get(formId=result["formId"]).execute()
print(getresult)

নোড.জেএস

ফর্ম/স্নিপেট/কনভার্ট_ফর্ম.জেএস
import path from 'node:path';
import {authenticate} from '@google-cloud/local-auth';
import {forms} from '@googleapis/forms';

/**
 * Creates a new form and then converts it into a quiz.
 */
async function convertForm() {
  // Authenticate with Google and get an authorized client.
  const authClient = await authenticate({
    keyfilePath: path.join(__dirname, 'credentials.json'),
    scopes: 'https://www.googleapis.com/auth/drive',
  });

  // Create a new Forms API client.
  const formsClient = forms({
    version: 'v1',
    auth: authClient,
  });

  // The initial form to be created.
  const newForm = {
    info: {
      title: 'Creating a new form for batchUpdate in Node',
    },
  };

  // Create the new form.
  const createResponse = await formsClient.forms.create({
    requestBody: newForm,
  });

  if (!createResponse.data.formId) {
    throw new Error('Failed to create form.');
  }

  console.log(`New formId was: ${createResponse.data.formId}`);

  // Request body to convert the form to a quiz.
  const updateRequest = {
    requests: [
      {
        updateSettings: {
          settings: {
            quizSettings: {
              isQuiz: true,
            },
          },
          // The updateMask specifies which fields to update.
          updateMask: 'quizSettings.isQuiz',
        },
      },
    ],
  };

  // Send the batch update request to convert the form to a quiz.
  const result = await formsClient.forms.batchUpdate({
    formId: createResponse.data.formId,
    requestBody: updateRequest,
  });

  console.log(result.data);
  return result.data;
}

পরবর্তী পদক্ষেপ

এখানে কিছু পরবর্তী পদক্ষেপ দেওয়া হল যা আপনি চেষ্টা করতে পারেন: