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

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

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

তুমি শুরু করার আগে

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

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

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

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

বিশ্রাম

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

নমুনা অনুরোধ শরীর

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

পাইথন

forms/snippets/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)

Node.js

forms/snippets/create_form.js
'use strict';

const path = require('path');
const google = require('@googleapis/forms');
const {authenticate} = require('@google-cloud/local-auth');

async function runSample(query) {
  const authClient = await authenticate({
    keyfilePath: path.join(__dirname, 'credentials.json'),
    scopes: 'https://www.googleapis.com/auth/drive',
  });
  const forms = google.forms({
    version: 'v1',
    auth: authClient,
  });
  const newForm = {
    info: {
      title: 'Creating a new form in Node',
    },
  };
  const res = await forms.forms.create({
    requestBody: newForm,
  });
  console.log(res.data);
  return res.data;
}

if (module === require.main) {
  runSample().catch(console.error);
}
module.exports = runSample;

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

আপনি Google ড্রাইভ API এর সাথে একটি বিদ্যমান ফর্ম নকল করতে পারেন যাতে সামগ্রীর পুনরায় ব্যবহার সহজ হয়৷ আপনি একটি Google ফর্ম URL-এ ফর্ম আইডি খুঁজে পেতে পারেন:

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

বিশ্রাম

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

পাইথন

forms/snippets/duplicate_form.py
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 সেটিংটি সত্যে সেট করতে একটি বিদ্যমান ফর্মে batch.update() পদ্ধতিতে কল করুন।

নমুনা অনুরোধ শরীর

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

পাইথন

forms/snippets/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)

Node.js

forms/snippets/convert_form.js
'use strict';

const path = require('path');
const google = require('@googleapis/forms');
const {authenticate} = require('@google-cloud/local-auth');

async function runSample(query) {
  const authClient = await authenticate({
    keyfilePath: path.join(__dirname, 'credentials.json'),
    scopes: 'https://www.googleapis.com/auth/drive',
  });
  const forms = google.forms({
    version: 'v1',
    auth: authClient,
  });
  const newForm = {
    info: {
      title: 'Creating a new form for batchUpdate in Node',
    },
  };
  const createResponse = await forms.forms.create({
    requestBody: newForm,
  });
  console.log('New formId was: ' + createResponse.data.formId);

  // Request body to convert form to a quiz
  const updateRequest = {
    requests: [
      {
        updateSettings: {
          settings: {
            quizSettings: {
              isQuiz: true,
            },
          },
          updateMask: 'quizSettings.isQuiz',
        },
      },
    ],
  };
  const res = await forms.forms.batchUpdate({
    formId: createResponse.data.formId,
    requestBody: updateRequest,
  });
  console.log(res.data);
  return res.data;
}

if (module === require.main) {
  runSample().catch(console.error);
}
module.exports = runSample;

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

এখানে কয়েকটি পরবর্তী ধাপ রয়েছে যা আপনি চেষ্টা করতে পারেন: