เรากำลังเปิดตัวการควบคุมแบบละเอียดสำหรับผู้ตอบเพื่อให้ผู้สร้างแบบฟอร์มควบคุมผู้ที่มีสิทธิ์ตอบได้มากขึ้น แบบฟอร์มที่สร้างด้วย API หลังจากวันที่ 31 มกราคม 2026 จะมีสถานะ "ไม่ได้เผยแพร่" โดยค่าเริ่มต้น ดูข้อมูลเพิ่มเติมได้ที่
การเปลี่ยนแปลง API ใน Google ฟอร์ม
ดึงแบบฟอร์มและคำตอบ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Google Forms API ช่วยให้คุณเรียกข้อมูลเนื้อหา การตั้งค่า และข้อมูลเมตาของแบบฟอร์ม รวมถึงคำตอบของแบบฟอร์มจากผู้ใช้งานปลายทางได้ หน้านี้จะอธิบายวิธีทํางานเหล่านี้
ก่อนเริ่มต้น
ทํางานต่อไปนี้ก่อนดําเนินการต่อในหน้านี้
- ตั้งค่าการให้สิทธิ์/การตรวจสอบสิทธิ์และข้อมูลเข้าสู่ระบบให้เสร็จสมบูรณ์ในคำแนะนำของโปรแกรมผู้ใช้งานช่วงแรก
ดึงข้อมูลเนื้อหาและข้อมูลเมตาของแบบฟอร์ม
หากต้องการเรียกข้อมูลเนื้อหา การตั้งค่า และข้อมูลเมตาของแบบฟอร์ม ให้เรียกใช้เมธอด forms.get()
พร้อมรหัสแบบฟอร์ม
หากต้องการเรียกข้อมูลคำตอบทั้งหมดจากแบบฟอร์ม ให้เรียกใช้เมธอด forms.responses.list()
ด้วยรหัสแบบฟอร์ม
หากต้องการเรียกข้อมูลคำตอบที่เฉพาะเจาะจงจากแบบฟอร์ม ให้เรียกใช้เมธอด forms.responses.get()
ด้วยรหัสแบบฟอร์มและรหัสคำตอบ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-04-09 UTC
[null,null,["อัปเดตล่าสุด 2025-04-09 UTC"],[],["The Google Forms API allows retrieving form data and responses. To begin, set up authorization/authentication. To get form content, settings, and metadata, use `forms.get()` with the form ID. To retrieve all responses, use `forms.responses.list()` with the form ID. For a single response, use `forms.responses.get()` with both the form ID and specific response ID. Python and Node.js code examples are provided for each action.\n"],null,["# Retrieve forms and responses\n\nThe Google Forms API lets you retrieve form content, settings and metadata,\nand the end-user form responses. This page describes how to perform these\ntasks.\n\nBefore you begin\n----------------\n\nPerform the following tasks before proceeding with the tasks on this page:\n\n- Complete authorization/authentication and credentials setup in the Early Adopter Program instructions.\n\nRetrieve form contents and metadata\n-----------------------------------\n\nTo retrieve the content, settings, and metadata of a form, call the\n[`forms.get()`](/workspace/forms/api/reference/rest/v1/forms/get) method with\nthe form ID. \n\n### Python\n\nforms/snippets/retrieve_contents.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/retrieve_contents.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.readonly\"\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)\nservice = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\n# Prints the title of the sample form:\nform_id = \"\u003cYOUR_FORM_ID\u003e\"\nresult = service.forms().get(formId=form_id).execute()\nprint(result)\n```\n\n### Node.js\n\nforms/snippets/get_form.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/get_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\nconst formID = '\u003cYOUR_FORM_ID\u003e';\n\nasync function runSample(query) {\n const auth = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/forms.body.readonly',\n });\n const forms = google.forms({\n version: 'v1',\n auth: auth,\n });\n const res = await forms.forms.get({formId: formID});\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\nRetrieve all form responses\n---------------------------\n\nTo retrieve all of the responses from a form, call the\n[`forms.responses.list()`](/workspace/forms/api/reference/rest/v1/forms.responses/list)\nmethod with the form ID. \n\n### Python\n\nforms/snippets/retrieve_all_responses.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/retrieve_all_responses.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.responses.readonly\"\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)\nservice = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\n# Prints the responses of your specified form:\nform_id = \"\u003cYOUR_FORM_ID\u003e\"\nresult = service.forms().responses().list(formId=form_id).execute()\nprint(result)\n```\n\n### Node.js\n\nforms/snippets/get_all_responses.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/get_all_responses.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\nconst formID = '\u003cYOUR_FORM_ID\u003e';\n\nasync function runSample(query) {\n const auth = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/forms.responses.readonly',\n });\n const forms = google.forms({\n version: 'v1',\n auth: auth,\n });\n const res = await forms.forms.responses.list({\n formId: formID,\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\nRetrieve a single form response\n-------------------------------\n\nTo retrieve a specific response from a form, call the\n[`forms.responses.get()`](/workspace/forms/api/reference/rest/v1/forms.responses/get)\nmethod with the form ID and the response ID. \n\n### Python\n\nforms/snippets/retrieve_single_response.py \n[View on GitHub](https://github.com/googleworkspace/python-samples/blob/main/forms/snippets/retrieve_single_response.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.responses.readonly\"\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)\nservice = discovery.build(\n \"forms\",\n \"v1\",\n http=creds.authorize(Http()),\n discoveryServiceUrl=DISCOVERY_DOC,\n static_discovery=False,\n)\n\n# Prints the specified response from your form:\nform_id = \"\u003cYOUR_FORM_ID\u003e\"\nresponse_id = \"\u003cYOUR_RESPONSE_ID\u003e\"\nresult = (\n service.forms()\n .responses()\n .get(formId=form_id, responseId=response_id)\n .execute()\n)\nprint(result)\n```\n\n### Node.js\n\nforms/snippets/get_single_response.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/forms/snippets/get_single_response.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\nconst formID = '\u003cYOUR_FORM_ID\u003e';\nconst responseID = '\u003cYOUR_RESPONSE_ID\u003e';\n\nasync function runSample(query) {\n const auth = await authenticate({\n keyfilePath: path.join(__dirname, 'credentials.json'),\n scopes: 'https://www.googleapis.com/auth/forms.responses.readonly',\n });\n const forms = google.forms({\n version: 'v1',\n auth: auth,\n });\n const res = await forms.forms.responses.get({\n formId: formID,\n responseId: responseID,\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```"]]