为了让表单创建者能够更好地控制哪些人可以回复,我们将为回复者引入精细的控制功能。2026 年 1 月 31 日之后使用该 API 创建的表单将默认处于未发布状态。如需了解详情,请参阅
Google 表单的 API 变更。
检索表单和回复
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Google Forms API,您可以检索表单内容、设置和元数据,以及最终用户的表单回复。本页介绍了如何执行这些任务。
准备工作
在继续执行本页面上的任务之前,请先执行以下任务:
- 按照抢先体验计划说明完成授权/身份验证和凭据设置。
检索表单内容和元数据
如需检索表单的内容、设置和元数据,请使用表单 ID 调用 forms.get()
方法。
如需检索表单中的所有回复,请使用表单 ID 调用 forms.responses.list()
方法。
如需从表单中检索特定回复,请使用表单 ID 和回复 ID 调用 forms.responses.get()
方法。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-04-09。
[null,null,["最后更新时间 (UTC):2025-04-09。"],[],["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```"]]