Để giúp người tạo biểu mẫu kiểm soát chặt chẽ hơn những người có thể trả lời, chúng tôi sẽ ra mắt chế độ kiểm soát chi tiết cho người trả lời. Theo mặc định, những biểu mẫu được tạo bằng API sau ngày 31 tháng 3 năm 2026 sẽ ở trạng thái chưa được xuất bản. Để tìm hiểu thêm, hãy xem bài viết Các thay đổi về API đối với Google Biểu mẫu.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Google Biểu mẫu API cho phép bạn truy xuất nội dung, chế độ cài đặt và siêu dữ liệu của biểu mẫu, cũng như câu trả lời của người dùng cuối cho biểu mẫu. Trang này mô tả cách thực hiện các tác vụ này.
Trước khi bắt đầu
Hãy thực hiện các việc sau trước khi tiếp tục thực hiện các việc trên trang này:
Hoàn tất quá trình uỷ quyền/xác thực và thiết lập thông tin đăng nhập theo hướng dẫn của Chương trình người dùng sớm.
Truy xuất nội dung và siêu dữ liệu của biểu mẫu
Để truy xuất nội dung, chế độ cài đặt và siêu dữ liệu của một biểu mẫu, hãy gọi phương thức forms.get() bằng mã nhận dạng biểu mẫu.
fromapiclientimportdiscoveryfromhttplib2importHttpfromoauth2clientimportclient,file,toolsSCOPES="https://www.googleapis.com/auth/forms.body.readonly"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)service=discovery.build("forms","v1",http=creds.authorize(Http()),discoveryServiceUrl=DISCOVERY_DOC,static_discovery=False,)# Prints the title of the sample form:form_id="<YOUR_FORM_ID>"result=service.forms().get(formId=form_id).execute()print(result)
importpathfrom'node:path';import{authenticate}from'@google-cloud/local-auth';import{forms}from'@googleapis/forms';// TODO: Replace with a valid form ID.constformID='<YOUR_FORM_ID>';/** * Retrieves the content of a form. */asyncfunctiongetForm(){// Authenticate with Google and get an authorized client.constauth=awaitauthenticate({keyfilePath:path.join(__dirname,'credentials.json'),scopes:'https://www.googleapis.com/auth/forms.body.readonly',});// Create a new Forms API client.constformsClient=forms({version:'v1',auth,});// Get the form content.constresult=awaitformsClient.forms.get({formId:formID});console.log(result.data);returnresult.data;}
Truy xuất tất cả câu trả lời của biểu mẫu
Để truy xuất tất cả các câu trả lời từ một biểu mẫu, hãy gọi phương thức forms.responses.list() bằng mã nhận dạng biểu mẫu.
fromapiclientimportdiscoveryfromhttplib2importHttpfromoauth2clientimportclient,file,toolsSCOPES="https://www.googleapis.com/auth/forms.responses.readonly"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)service=discovery.build("forms","v1",http=creds.authorize(Http()),discoveryServiceUrl=DISCOVERY_DOC,static_discovery=False,)# Prints the responses of your specified form:form_id="<YOUR_FORM_ID>"result=service.forms().responses().list(formId=form_id).execute()print(result)
importpathfrom'node:path';import{authenticate}from'@google-cloud/local-auth';import{forms}from'@googleapis/forms';// TODO: Replace with a valid form ID.constformID='<YOUR_FORM_ID>';/** * Retrieves all responses from a form. */asyncfunctiongetAllResponses(){// Authenticate with Google and get an authorized client.constauth=awaitauthenticate({keyfilePath:path.join(__dirname,'credentials.json'),scopes:'https://www.googleapis.com/auth/forms.responses.readonly',});// Create a new Forms API client.constformsClient=forms({version:'v1',auth,});// Get the list of responses for the form.constresult=awaitformsClient.forms.responses.list({formId:formID,});console.log(result.data);returnresult.data;}
Truy xuất một câu trả lời duy nhất trong biểu mẫu
Để truy xuất một phản hồi cụ thể từ biểu mẫu, hãy gọi phương thức forms.responses.get() bằng mã biểu mẫu và mã phản hồi.
fromapiclientimportdiscoveryfromhttplib2importHttpfromoauth2clientimportclient,file,toolsSCOPES="https://www.googleapis.com/auth/forms.responses.readonly"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)service=discovery.build("forms","v1",http=creds.authorize(Http()),discoveryServiceUrl=DISCOVERY_DOC,static_discovery=False,)# Prints the specified response from your form:form_id="<YOUR_FORM_ID>"response_id="<YOUR_RESPONSE_ID>"result=(service.forms().responses().get(formId=form_id,responseId=response_id).execute())print(result)
importpathfrom'node:path';import{authenticate}from'@google-cloud/local-auth';import{forms}from'@googleapis/forms';// TODO: Replace with a valid form ID.constformID='<YOUR_FORM_ID>';// TODO: Replace with a valid response ID.constresponseID='<YOUR_RESPONSE_ID>';/** * Retrieves a single response from a form. */asyncfunctiongetSingleResponse(){// Authenticate with Google and get an authorized client.constauth=awaitauthenticate({keyfilePath:path.join(__dirname,'credentials.json'),scopes:'https://www.googleapis.com/auth/forms.responses.readonly',});// Create a new Forms API client.constformsClient=forms({version:'v1',auth,});// Get the specified response from the form.constresult=awaitformsClient.forms.responses.get({formId:formID,responseId:responseID,});console.log(result.data);returnresult.data;}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-16 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,[]]