برای اینکه به سازندگان فرم کنترل بیشتری بر روی افرادی که میتوانند پاسخ دهند، کنترلهای جزئی را برای پاسخدهندگان معرفی میکنیم. فرم هایی که پس از 31 ژانویه 2026 با API ایجاد می شوند، به طور پیش فرض دارای وضعیت منتشر نشده خواهند بود. برای کسب اطلاعات بیشتر، تغییرات API در Google Forms را ببینید.
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
راه اندازی یک پروژه Apps Script برای فراخوانی مستقیم Google Forms API از طریق تماس REST ساده است. با فرض اینکه قبلاً یک پروژه Google Cloud را پیکربندی کرده اید، موارد زیر را انجام دهید:
یک پروژه Apps Script جدید ایجاد کنید.
شماره پروژه Google Cloud مرتبط را تغییر دهید تا با پروژه ای که برای Google Forms API فعال کرده اید مطابقت داشته باشد.
فایل Manifest ( appsscript.json ) را ویرایش کنید تا دامنه های OAuth لازم را اضافه کنید.
کد Apps Script را برای واکشی یک نشانه OAuth و برقراری تماس REST با استفاده از نشانه اضافه کنید.
در اینجا یک توضیح سریع از این مراحل است.
یک پروژه Apps Script جدید ایجاد و پیکربندی کنید
با استفاده از همان شناسه Google که پروژه GCP خود را با آن پیکربندی کردهاید، به داشبورد Apps Script بروید، سپس پروژه جدید را کلیک کنید.
پس از باز شدن پروژه، settings تنظیمات پروژه کلیک کنید.
کادر بررسی نمایش فایل مانیفست "appsscript.json" در ویرایشگر را انتخاب کنید.
در بخش پروژه Google Cloud Platform (GCP) روی تغییر پروژه کلیک کنید و شماره پروژه GCP را که برای Forms API پیکربندی کردهاید وارد کنید.
پروژه Apps Script شما اکنون برای دسترسی به Google Forms API پیکربندی شده است. مرحله بعدی مورد نیاز اضافه کردن دامنه های OAuth مناسب است.
دامنه های OAuth را اضافه کنید
برای ایجاد یک نشانه OAuth با محدوده مناسب در Apps Script، باید محدوده های مورد نیاز را در فایل مانیفست پروژه تنظیم کنید.
save پروژه کلیک کنید و در صورت نیاز هرگونه خطای نحوی را تصحیح کنید. اکنون پروژه شما باید بتواند از طریق تماس REST با Google Forms API تماس بگیرد.
کد Apps Script را برای تماس با API اضافه کنید
قبل از نوشتن کد برای فراخوانی یک فرم، باید فرمی را که متعلق به شما است و دارای پاسخ است شناسایی کنید و شناسه فرم آن را یادداشت کنید. شناسه فرم را می توان در URL هنگام ویرایش فرم پیدا کرد:
https://docs.google.com/forms/d/<FORM_ID>/edit
برای فراخوانی API، از تماس Apps Script UrlFetchApp استفاده خواهید کرد.
تاریخ آخرین بهروزرسانی 2025-04-09 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-04-09 بهوقت ساعت هماهنگ جهانی."],[],["To use the Google Forms API via REST calls in Apps Script: first, create a new Apps Script project and link it to your Google Cloud project enabled for the Forms API. Then, edit the `appsscript.json` manifest file to include required OAuth scopes, such as `script.external_request` and `forms.responses.readonly`. Finally, use `UrlFetchApp` in your Apps Script code to call the API, getting an OAuth token with `ScriptApp.getOAuthToken()` and a form ID. Run and authorize the script to see API responses.\n"],null,["# Set up an Apps Script project\n\nSetting up an Apps Script project to call the Google Forms API directly through a\nREST call is straightforward. Assuming you have already configured a\nGoogle Cloud project, do the following:\n\n1. Create a new Apps Script project.\n2. Change the associated Google Cloud project number to match the project you enabled for the Google Forms API.\n3. Edit the Manifest file (`appsscript.json`) to add the necessary OAuth scopes.\n4. Add Apps Script code to fetch an OAuth token and make a REST call using the token.\n\nHere's a quick walkthrough of these steps.\n\nCreate and configure a new Apps Script project\n----------------------------------------------\n\n1. Using the same Google ID that you configured your GCP project with, go to the [Apps Script Dashboard](https://script.google.com), then click **New project**.\n2. Once your project is open, click settings Project Settings.\n3. Select the **Show \"appsscript.json\" manifest file in editor** checkbox.\n4. In the **Google Cloud Platform (GCP) Project** section, click **Change\n project** and enter the GCP project number that you configured for the Forms API.\n\nYour Apps Script project is now configured to access the Google Forms API. The next\nrequired step is to add the proper OAuth scopes.\n\nAdd OAuth scopes\n----------------\n\nTo generate a properly scoped OAuth token in Apps Script, you need to set the\nrequired scopes in the project's manifest file.\n\n1. In the editor, open `appsscript.json`.\n2. Add the scopes to the body of the manifest.\n\n **Note:** Each API method has its own specific OAuth scope requirements ([example](/workspace/forms/api/reference/rest/v1/forms/get#authorization-scopes)). You only need to include scopes for the methods you use. For instance, if you only plan to fetch form responses, you only need `forms.responses.readonly`. The `script.external_request` scope is required to allow Apps Script to call an external REST service. \n\n {\n ...\n \"oauthScopes\": [\n \"https://www.googleapis.com/auth/script.external_request\",\n \"https://www.googleapis.com/auth/drive\",\n \"https://www.googleapis.com/auth/drive.readonly\",\n \"https://www.googleapis.com/auth/forms.body\",\n \"https://www.googleapis.com/auth/forms.body.readonly\",\n \"https://www.googleapis.com/auth/forms.responses.readonly\"\n ],\n ...\n }\n\n3. Click save Save project and correct\n any syntax errors if needed. Your project should now be able to call the\n Google Forms API via a REST call.\n\nAdd Apps Script code to call the API\n------------------------------------\n\nBefore writing the code to call a form, you need to identify a form that you\nown that has responses and take note of its form ID. The form ID can be found\nin the URL when editing the form:\n\n`https://docs.google.com/forms/d/\u003cFORM_ID\u003e/edit`\n\nTo call the API, you will use an Apps Script `UrlFetchApp` call.\n\n1. Open **Code.gs** and add the following code:\n\n forms-api/snippets/retrieve_all_responses.gs \n [View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/forms-api/snippets/retrieve_all_responses.gs) \n\n ```javascript\n function callFormsAPI() {\n console.log('Calling the Forms API!');\n var formId = '\u003cYOUR_FORM_ID\u003e';\n\n // Get OAuth Token\n var OAuthToken = ScriptApp.getOAuthToken();\n console.log('OAuth token is: ' + OAuthToken);\n var formsAPIUrl = 'https://forms.googleapis.com/v1/forms/' + formId + '/' + 'responses';\n console.log('formsAPIUrl is: ' + formsAPIUrl);\n var options = {\n 'headers': {\n Authorization: 'Bearer ' + OAuthToken,\n Accept: 'application/json'\n },\n 'method': 'get'\n }; \n var response = UrlFetchApp.fetch(formsAPIUrl, options);\n console.log('Response from forms.responses was: ' + response);\n }\n ```\n2. Replace `YOUR_FORM_ID` with the value that you noted earlier.\n\n Example: `var formId = 'tL5ygBC8zpbTnTp76JCZdIg80hA-cnpbTnTjnsewCKJH';`\n3. Click save **Save project** and correct\n any syntax errors if needed.\n\nTest the code\n-------------\n\n1. Click play_arrow **Run**.\n2. Authorize the project as needed using the same Google ID as before.\n\nOnce it starts, you should see a response in the **Execution log** similar to\nthis: \n\n```\nExecution started\nCalling the Forms API!\nOAuth token is: ya29.a0ARrdaM8IMjtlv…\nformsAPIUrl is: https://forms.googleapis.com/v1beta/forms/…/responses\nResponse from Forms.responses was: {\n\"responses\": [\n {\n \"responseId\":\"...\",\n \"createTime\": \"2021-03-25T01:23:58.146Z\",\n \"lastSubmittedTime\": \"2021-03-25T01:23:58.146607Z\",\n \"answers\": {\n \"1e9b0ead\": {\n \"questionId\": \"1e9b0ead\",\n \"textAnswers\": {\n \"answers\": [\n {\n \"value\": \"Red\"\n }\n ]\n }\n },\n \"773ed8f3\": {\n \"questionId\": \"773ed8f3\",\n \"textAnswers\": {\n \"answers\": [\n {\n \"value\": \"Tesla\"\n }\n ]\n }\n }\n }\n }\n ]\n}\nExecution completed\n```\n\nNext steps\n----------\n\nOnce you've successfully called the API with Apps Script, consult the\n[reference documentation](/workspace/forms/api/reference/rest) and experiment\nwith making other calls to the API."]]