برای اینکه به سازندگان فرم کنترل بیشتری بر روی افرادی که میتوانند پاسخ دهند، کنترلهای جزئی را برای پاسخدهندگان معرفی میکنیم. فرم هایی که پس از 31 ژانویه 2026 با API ایجاد می شوند، به طور پیش فرض دارای وضعیت منتشر نشده خواهند بود. برای کسب اطلاعات بیشتر،
تغییرات API در Google Forms را ببینید.
یک فرم یا مسابقه ایجاد کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این صفحه نحوه انجام این وظایف شامل فرم ها را شرح می دهد:
- یک فرم جدید ایجاد کنید
- یک فرم موجود را کپی کنید
- تبدیل فرم به مسابقه
قبل از شروع
قبل از ادامه کار در این صفحه، کارهای زیر را انجام دهید:
- مجوز کامل یا تأیید اعتبار و تنظیمات اعتبار را در دستورالعمل های Early Adopter Program کامل کنید.
- نمای کلی Forms API را بخوانید.
ایجاد اولیه یک فرم فقط به یک فیلد عنوان نیاز دارد—هر فیلد دیگر در درخواست نادیده گرفته می شود. برای ایجاد محتوا و فراداده یک فرم یا به روز رسانی، از متد batchUpdate()
استفاده کنید. برای اطلاعات بیشتر به به روز رسانی فرم یا مسابقه مراجعه کنید.
استراحت
متد forms.create()
را فقط با عنوان فراخوانی کنید.
نمونه بدنه درخواست
{
"info": {
"title": "My new form"
}
}
میتوانید یک فرم موجود را با API Google Drive کپی کنید تا استفاده مجدد از محتوا آسانتر شود. میتوانید شناسه فرم را در URL فرمهای Google پیدا کنید:
https://docs.google.com/forms/d/FORM_ID/edit
استراحت
با شناسه فرمی که میخواهید کپی کنید، متد files.copy()
API Google Drive را فراخوانی کنید.
برای ایجاد یک مسابقه، ابتدا فرمی را همانطور که در ایجاد فرم جدید توضیح داده شده ایجاد کنید، سپس تنظیمات فرم را به روز کنید. به روز رسانی به شناسه فرم نیاز دارد.
استراحت
متد batch.update()
را در یک فرم موجود فراخوانی کنید تا تنظیمات isQuiz
را روی true تنظیم کنید.
نمونه بدنه درخواست
{
"requests": [
{
"updateSettings": {
"settings": {
"quizSettings": {
"isQuiz": True
}
},
"updateMask": "quizSettings.isQuiz"
}
}
]
}
مراحل بعدی
در اینجا چند مرحله بعدی وجود دارد که ممکن است امتحان کنید:
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-06-27 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-06-27 بهوقت ساعت هماهنگ جهانی."],[],["This document details how to create, duplicate, and convert forms. To create a new form, use the `forms.create()` method with a title. To duplicate a form, employ the Drive API's `files.copy()` method, specifying the form's ID. To convert a form into a quiz, use the `batch.update()` method to change the `isQuiz` setting to true, also requires the form ID. Authorization and authentication setup as indicated in the instructions is required.\n"],null,["# Create a form or quiz\n\nThis page describes how to perform these tasks involving forms:\n\n- Create a new form\n- Duplicate an existing form\n- Convert a form to a quiz\n\nBefore you begin\n----------------\n\nDo the following tasks before proceeding with the tasks on this page:\n\n- Complete authorization or authentication and credentials setup in the Early Adopter Program instructions.\n- Read the [Forms API overview](/workspace/forms/api/guides).\n\nCreate a new form\n-----------------\n\nThe initial creation of a form only requires a title field---any other fields\nin the request will be ignored. To build out the content and metadata of a\nform or make updates, use the `batchUpdate()` method. See\n[Update a form or quiz](/workspace/forms/api/guides/update-form-quiz) for more\ninformation. \n\n### REST\n\nCall the [`forms.create()`](/workspace/forms/api/reference/rest/v1/forms/create)\nmethod with only a title.\n\n**Sample request body** \n\n {\n \"info\": {\n \"title\": \"My new form\"\n }\n }\n\n### Python\n\nforms/snippets/create_form.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/create_form.py) \n\n```python\nfrom apiclient import discovery\nfrom httplib2 import Http\nfrom oauth2client import client, file, tools\n\nSCOPES = \"https://www.googleapis.com/auth/drive\"\nDISCOVERY_DOC = \"https://forms.googleapis.com/$discovery/rest?version=v1\"\n\nstore = file.Storage(\"token.json\")\ncreds = None\nif not creds or creds.invalid:\n flow = client.flow_from_clientsecrets(\"client_secrets.json\", SCOPES)\n creds = tools.run_flow(flow, store)\n\nform_service = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\nform = {\n \"info\": {\n \"title\": \"My new form\",\n },\n}\n# Prints the details of the sample form\nresult = form_service.forms().create(body=form).execute()\nprint(result)\n```\n\n### Node.js\n\nforms/snippets/create_form.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/create_form.js) \n\n```javascript\n'use strict';\n\nconst path = require('path');\nconst google = require('@googleapis/forms');\nconst {authenticate} = require('@google-cloud/local-auth');\n\nasync function runSample(query) {\n const authClient = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/drive',\n });\n const forms = google.forms({\n version: 'v1',\n auth: authClient,\n });\n const newForm = {\n info: {\n title: 'Creating a new form in Node',\n },\n };\n const res = await forms.forms.create({\n requestBody: newForm,\n });\n console.log(res.data);\n return res.data;\n}\n\nif (module === require.main) {\n runSample().catch(console.error);\n}\nmodule.exports = runSample;\n```\n\nDuplicate an existing form\n--------------------------\n\nYou can duplicate an existing form with the\n[Google Drive API](/workspace/drive/api/v3/about-sdk) to make content re-use\neasier. You can find the form ID in a Google Forms URL:\n\n`https://docs.google.com/forms/d/FORM_ID/edit` \n\n### REST\n\nCall the Google Drive API's\n[`files.copy()`](/workspace/drive/v3/reference/files/copy)\nmethod with the ID of the form you want to copy.\n\n### Python\n\nforms/snippets/duplicate_form.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/duplicate_form.py) \n\n```python\nimport os.path\n\nfrom google.auth.transport.requests import Request\nfrom google.oauth2.credentials import Credentials\nfrom google_auth_oauthlib.flow import InstalledAppFlow\nfrom googleapiclient.discovery import build\n\n# If modifying these scopes, delete the file token.json.\nSCOPES = [\"https://www.googleapis.com/auth/drive\"]\n\n\ndef main():\n \"\"\"Shows copy file example in Drive v3 API.\n Prints the name, id and other data of the copied file.\n \"\"\"\n creds = None\n if os.path.exists(\"token.json\"):\n creds = Credentials.from_authorized_user_file(\"token.json\", SCOPES)\n # If there are no (valid) credentials available, let the user log in.\n if not creds or not creds.valid:\n if creds and creds.expired and creds.refresh_token:\n creds.refresh(Request())\n else:\n flow = InstalledAppFlow.from_client_secrets_file(\n \"client_secrets.json\", SCOPES\n )\n creds = flow.run_local_server(port=0)\n # Save the credentials for the next run\n with open(\"token.json\", \"w\") as token:\n token.write(creds.to_json())\n\n service = build(\"drive\", \"v3\", credentials=creds)\n\n # Call the Drive v3 API\n origin_file_id = \"1ox-6vHFeKpC6mon-tL5ygBC8zpbTnTp76JCZdIg80hA\" # example ID\n copied_file = {\"title\": \"my_copy\"}\n results = (\n service.files().copy(fileId=origin_file_id, body=copied_file).execute()\n )\n print(results)\n\n\nif __name__ == \"__main__\":\n main()\n```\n\nConvert a form to a quiz\n------------------------\n\nTo create a quiz, first create a form as described in [Create a new form](#create_a_new_form),\nthen update the form's settings. The update requires the form ID. \n\n### REST\n\nCall the\n[`batch.update()`](/workspace/forms/api/reference/rest/v1/forms/batchUpdate)\nmethod on an existing form to set the `isQuiz` setting to true.\n\n**Sample request body** \n\n {\n \"requests\": [\n {\n \"updateSettings\": {\n \"settings\": {\n \"quizSettings\": {\n \"isQuiz\": True\n }\n },\n \"updateMask\": \"quizSettings.isQuiz\"\n }\n }\n ]\n }\n\n### Python\n\nforms/snippets/convert_form.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/convert_form.py) \n\n```python\nfrom apiclient import discovery\nfrom httplib2 import Http\nfrom oauth2client import client, file, tools\n\nSCOPES = \"https://www.googleapis.com/auth/forms.body\"\nDISCOVERY_DOC = \"https://forms.googleapis.com/$discovery/rest?version=v1\"\n\nstore = file.Storage(\"token.json\")\ncreds = None\nif not creds or creds.invalid:\n flow = client.flow_from_clientsecrets(\"client_secrets.json\", SCOPES)\n creds = tools.run_flow(flow, store)\n\nform_service = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\nform = {\n \"info\": {\n \"title\": \"My new quiz\",\n }\n}\n\n# Creates the initial form\nresult = form_service.forms().create(body=form).execute()\n\n# JSON to convert the form into a quiz\nupdate = {\n \"requests\": [\n {\n \"updateSettings\": {\n \"settings\": {\"quizSettings\": {\"isQuiz\": True}},\n \"updateMask\": \"quizSettings.isQuiz\",\n }\n }\n ]\n}\n\n# Converts the form into a quiz\nquestion_setting = (\n form_service.forms()\n .batchUpdate(formId=result[\"formId\"], body=update)\n .execute()\n)\n\n# Print the result to see it's now a quiz\ngetresult = form_service.forms().get(formId=result[\"formId\"]).execute()\nprint(getresult)\n```\n\n### Node.js\n\nforms/snippets/convert_form.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/convert_form.js) \n\n```javascript\n'use strict';\n\nconst path = require('path');\nconst google = require('@googleapis/forms');\nconst {authenticate} = require('@google-cloud/local-auth');\n\nasync function runSample(query) {\n const authClient = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/drive',\n });\n const forms = google.forms({\n version: 'v1',\n auth: authClient,\n });\n const newForm = {\n info: {\n title: 'Creating a new form for batchUpdate in Node',\n },\n };\n const createResponse = await forms.forms.create({\n requestBody: newForm,\n });\n console.log('New formId was: ' + createResponse.data.formId);\n\n // Request body to convert form to a quiz\n const updateRequest = {\n requests: [\n {\n updateSettings: {\n settings: {\n quizSettings: {\n isQuiz: true,\n },\n },\n updateMask: 'quizSettings.isQuiz',\n },\n },\n ],\n };\n const res = await forms.forms.batchUpdate({\n formId: createResponse.data.formId,\n requestBody: updateRequest,\n });\n console.log(res.data);\n return res.data;\n}\n\nif (module === require.main) {\n runSample().catch(console.error);\n}\nmodule.exports = runSample;\n```\n\nNext steps\n----------\n\nHere are a few next steps you might try:\n\n- To add or update form content, refer to [Update a form or quiz](/workspace/forms/api/guides/update-form-quiz).\n- To view form information or responses, refer to [Retrieve forms and responses](/workspace/forms/api/guides/retrieve-forms-responses).\n- To publish the form and manage responders, refer to [Publish and manage responders](/workspace/forms/api/guides/publish-form)."]]