لمنح صنّاع النماذج مزيدًا من التحكّم في تحديد المستخدمين الذين يمكنهم الردّ، نقدّم عناصر تحكّم دقيقة للمجيبين. ستظهر النماذج التي تم إنشاؤها باستخدام واجهة برمجة التطبيقات بعد 31 كانون الثاني (يناير) 2026 في حالة "غير منشور" تلقائيًا. لمزيد من المعلومات، يُرجى الاطّلاع على تغييرات واجهة برمجة التطبيقات في "نماذج Google".
لا يتطلّب الإنشاء الأولي لنموذج سوى حقل العنوان، وسيتم تجاهل أي حقول أخرى في الطلب. لإنشاء محتوى وبيانات وصفية لجدول batchUpdate() أو إجراء تعديلات عليه، استخدِم الطريقة batchUpdate(). اطّلِع على مقالة تعديل نموذج أو اختبار للحصول على مزيد من المعلومات.
fromapiclientimportdiscoveryfromhttplib2importHttpfromoauth2clientimportclient,file,toolsSCOPES="https://www.googleapis.com/auth/drive"DISCOVERY_DOC="https://forms.googleapis.com/$discovery/rest?version=v1"store=file.Storage("token.json")creds=Noneifnotcredsorcreds.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 formresult=form_service.forms().create(body=form).execute()print(result)
'use strict';constpath=require('path');constgoogle=require('@googleapis/forms');const{authenticate}=require('@google-cloud/local-auth');asyncfunctionrunSample(query){constauthClient=awaitauthenticate({keyfilePath:path.join(__dirname,'credentials.json'),scopes:'https://www.googleapis.com/auth/drive',});constforms=google.forms({version:'v1',auth:authClient,});constnewForm={info:{title:'Creating a new form in Node',},};constres=awaitforms.forms.create({requestBody:newForm,});console.log(res.data);returnres.data;}if(module===require.main){runSample().catch(console.error);}module.exports=runSample;
تكرار نموذج حالي
يمكنك تكرار نموذج حالي باستخدام Google Drive API لتسهيل إعادة استخدام المحتوى. يمكنك العثور على معرّف النموذج في عنوان URL لخدمة "نماذج Google":
https://docs.google.com/forms/d/FORM_ID/edit
REST
استخدِم files.copy()
طريقة Google Drive API مع رقم تعريف النموذج الذي تريد نسخه.
importos.pathfromgoogle.auth.transport.requestsimportRequestfromgoogle.oauth2.credentialsimportCredentialsfromgoogle_auth_oauthlib.flowimportInstalledAppFlowfromgoogleapiclient.discoveryimportbuild# If modifying these scopes, delete the file token.json.SCOPES=["https://www.googleapis.com/auth/drive"]defmain():"""Shows copy file example in Drive v3 API. Prints the name, id and other data of the copied file. """creds=Noneifos.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.ifnotcredsornotcreds.valid:ifcredsandcreds.expiredandcreds.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 runwithopen("token.json","w")astoken:token.write(creds.to_json())service=build("drive","v3",credentials=creds)# Call the Drive v3 APIorigin_file_id="1ox-6vHFeKpC6mon-tL5ygBC8zpbTnTp76JCZdIg80hA"# example IDcopied_file={"title":"my_copy"}results=(service.files().copy(fileId=origin_file_id,body=copied_file).execute())print(results)if__name__=="__main__":main()
تحويل نموذج إلى اختبار
لإنشاء اختبار، عليك أولاً إنشاء نموذج كما هو موضّح في مقالة إنشاء نموذج جديد، ثم تعديل إعدادات النموذج. يتطلّب التعديل رقم تعريف النموذج.
REST
استخدِم الأسلوب
batch.update()
في نموذج حالي لضبط الإعداد isQuiz على "صحيح".
fromapiclientimportdiscoveryfromhttplib2importHttpfromoauth2clientimportclient,file,toolsSCOPES="https://www.googleapis.com/auth/forms.body"DISCOVERY_DOC="https://forms.googleapis.com/$discovery/rest?version=v1"store=file.Storage("token.json")creds=Noneifnotcredsorcreds.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 formresult=form_service.forms().create(body=form).execute()# JSON to convert the form into a quizupdate={"requests":[{"updateSettings":{"settings":{"quizSettings":{"isQuiz":True}},"updateMask":"quizSettings.isQuiz",}}]}# Converts the form into a quizquestion_setting=(form_service.forms().batchUpdate(formId=result["formId"],body=update).execute())# Print the result to see it's now a quizgetresult=form_service.forms().get(formId=result["formId"]).execute()print(getresult)
'use strict';constpath=require('path');constgoogle=require('@googleapis/forms');const{authenticate}=require('@google-cloud/local-auth');asyncfunctionrunSample(query){constauthClient=awaitauthenticate({keyfilePath:path.join(__dirname,'credentials.json'),scopes:'https://www.googleapis.com/auth/drive',});constforms=google.forms({version:'v1',auth:authClient,});constnewForm={info:{title:'Creating a new form for batchUpdate in Node',},};constcreateResponse=awaitforms.forms.create({requestBody:newForm,});console.log('New formId was: '+createResponse.data.formId);// Request body to convert form to a quizconstupdateRequest={requests:[{updateSettings:{settings:{quizSettings:{isQuiz:true,},},updateMask:'quizSettings.isQuiz',},},],};constres=awaitforms.forms.batchUpdate({formId:createResponse.data.formId,requestBody:updateRequest,});console.log(res.data);returnres.data;}if(module===require.main){runSample().catch(console.error);}module.exports=runSample;
تاريخ التعديل الأخير: 2025-06-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 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)."]]