이 페이지에서는 양식과 관련된 다음 작업을 수행하는 방법을 설명합니다.
- 응답자가 액세스할 수 있도록 양식 게시하기
- 양식 응답자 찾기
- 더 많은 응답자와 양식 공유하기
- 양식에서 응답자 삭제하기
- 양식이 '링크가 있는 모든 사용자'의 응답을 허용하는지 확인
- 양식 닫기
- 양식 게시 취소하기
- 양식 응답 수락 중지하기
- 양식이 기존 양식인지 확인
시작하기 전에
이 페이지의 작업을 진행하기 전에 다음 작업을 수행하세요.
양식 ID를 가져옵니다. 양식 ID는
forms.create
를 사용하여 양식을 만들 때 응답의formId
필드에 반환됩니다.
응답자가 액세스할 수 있도록 양식 게시하기
forms.setPublishSettings
메서드를 사용하여 기존 양식을 게시할 수 있습니다.
양식 ID를 사용하여
forms.setPublishSettings
메서드를 호출합니다.
REST
샘플 요청 본문
{
"publishSettings": {
"isPublished": true,
"isAcceptingResponses": true
}
}
Apps Script
/**
* Publishes a Google Form using its URL.
*/
function publishMyForm() {
// Replace with the URL of your Google Form
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
try {
const form = FormApp.openByUrl(formUrl);
// Publish the form. This also enables accepting responses.
form.setPublished(true);
Logger.log(`Form "${form.getTitle()}" published successfully.`);
// Optional: Verify the state
if (form.isPublished()) {
Logger.log('Form is now published.');
}
if (form.isAcceptingResponses()) {
Logger.log('Form is now accepting responses.')
}
} catch (error) {
Logger.log(`Error publishing form: ${error}`);
}
}
Python
Node.js
양식 응답자 찾기
Form.getPublishedReaders()를 사용하여 응답자 액세스 권한(PUBLISHED_READER 역할)이 있는 모든 사용자의 목록을 가져올 수 있습니다. 그러면 사용자 객체 배열이 반환됩니다.
REST
요청 URL에 쿼리 매개변수 includePermissionsForView=published
를 추가합니다.
Apps Script
/**
* Gets and logs the email addresses of all responders for a form.
*/
function listResponders() {
// Replace with the URL of your Google Form
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
try {
const form = FormApp.openByUrl(formUrl);
// Get the array of User objects representing responders
const responders = form.getPublishedReaders();
// Log the responders
Logger.log("Following can respond to the form");
responders.forEach(responder => Logger.log(responder.getEmail()));
return responders;
} catch (error) {
Logger.log(`Error getting responders: ${error}`);
}
}
Python
Node.js
더 많은 응답자와 양식 공유하기
응답자가 양식을 열고 응답할 수 있도록 양식에 응답자를 추가하려면 Drive permissions.create
메서드를 사용하면 됩니다.
양식 ID와 액세스 설정을 사용하여
permissions.create
메서드를 호출합니다.
REST
샘플 요청 본문
{
"view": "published",
"role": "reader",
"type": "user",
"emailAddress": "user@example.com"
}
Apps Script
/**
* Adds a single responder to a form using their email address.
*/
function `addSingleResponderByEmail()` {
// Replace with the URL of your Google Form
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
// Replace with the responder's email address
const responderEmail = 'responder@example.com';
try {
const form = FormApp.openByUrl(formUrl);
// Add the user as a responder
form.addPublishedReader(responderEmail);
Logger.log(`Added ${responderEmail} as a responder to form "${
form.getTitle()}".`);
} catch (error) {
Logger.log(`Error adding responder: ${error}`);
}
}
Python
Node.js
양식에서 응답자 삭제하기
이메일 주소를 사용하거나 User 객체를 사용하여 개별 응답자를 삭제할 수 있습니다. 응답자를 삭제하면 도메인 공유 또는 공유 드라이브 액세스와 같은 다른 방법으로 액세스할 수 있는 경우가 아니라면 응답자가 양식을 보고 제출할 수 있는 권한이 취소됩니다.
이메일 주소로 응답자 한 명 삭제하기
REST
DELETE https://www.googleapis.com/drive/v3/files/{fileId}/permissions/PERMISSION
permissionID는 앞에서 설명한 대로 'listing responders'를 통해 확인할 수 있습니다.
Apps Script
/**
* Removes a single responder from a form using their email address.
*/
function `removeSingleResponderByEmail()` {
// Replace with the URL of your Google Form
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
// Replace with the responder's email address to remove
const responderEmailToRemove = 'responder-to-remove@example.com';
try {
const form = FormApp.openByUrl(formUrl);
// Remove the user as a responder
form.removePublishedReader(responderEmailToRemove);
Logger.log(`Removed ${responderEmailToRemove} as a responder from form "${
form.getTitle()}".`);
} catch (error) {
Logger.log(`Error removing responder: ${error}`);
}
}
Python
Node.js
양식이 '링크가 있는 모든 사용자'의 응답을 수락하는지 확인합니다.
양식이 링크가 있는 모든 사용자의 응답을 허용하는지 확인하려면 Drive 고급 서비스를 사용 설정해야 합니다.
- Drive 고급 서비스를 사용 설정합니다.
- Apps Script 프로젝트를 엽니다.
- 서비스 (서비스 옆에 있는 더하기 아이콘)를 클릭합니다.
- Drive API를 찾아 추가를 클릭합니다.
- 추가를 클릭합니다.
Apps Script
function `isAnyoneWithLinkResponder`(formId) {
let permissions = Drive.Permissions.list(formId, { includePermissionsForView: 'published' }).permissions;
if (permissions) {
for (const permission of permissions) {
if (permission.type === 'anyone' && permission.view === 'published' && permission.role === 'reader') {
return true;
}
}
}
return false;
}
Python
Node.js
'링크가 있는 모든 사용자'가 양식에 응답할 수 있도록 설정하려면 다음 단계를 따르세요.
Apps Script
function `setAnyoneWithLinkResponder`(formId) {
Drive.Permissions.create({
type: 'anyone',
view: 'published',
role: 'reader',
}, formId);
}
Python
Node.js
'링크가 있는 모든 사용자'가 양식에 응답할 수 있는 기능을 삭제하려면 다음 단계를 따르세요.
Apps Script
function `removeAnyoneWithLinkResponder`(formId) {
let permissions = Drive.Permissions.list(formId, { includePermissionsForView: 'published' }).permissions;
if (permissions) {
for (const permission of permissions) {
if (permission.type === 'anyone' && permission.role === 'reader') {
Drive.Permissions.remove(formId, permission.id);
}
}
}
}
Python
Node.js
양식 닫기
양식을 게시 취소하려면 Forms.setPublished(false) 메서드를 사용합니다. {/apps-script/reference/forms/form#setpublishedenabled} 양식을 게시 취소하면 양식을 사용할 수 없게 되며 응답 수락이 자동으로 중지됩니다.
REST
샘플 요청 본문
POST https://forms.googleapis.com/v1/forms/{formId}:setPublishSettings
{
"publishSettings": {
"publishState": {
"isPublished": false
}
}
}
Apps Script
/**
* Unpublishes a Google Form using its URL.
*/
function unpublishMyForm() {
// Replace with the URL of your Google Form
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
try {
const form = FormApp.openByUrl(formUrl);
// Unpublish the form. This also disables accepting responses.
form.setPublished(false);
Logger.log(`Form "${form.getTitle()}" unpublished successfully.`);
// Optional: Verify the state
if (!form.isPublished()) {
Logger.log('Form is now unpublished.');
}
if (!form.isAcceptingResponses()) {
Logger.log('Form is no longer accepting responses.');
}
} catch (error) {
Logger.log(`Error unpublishing form: ${error}`);
}
}
Python
Node.js
양식을 게시 취소하지 않고 양식의 응답 수락을 중지하려면 Form.setAcceptingResponses(false)
메서드를 사용하면 됩니다.
양식 응답자에게는 닫힌 양식 페이지와 메시지가 표시됩니다.
REST
샘플 요청 본문
POST https://forms.googleapis.com/v1/forms/{formId}:setPublishSettings
{
"publishSettings": {
"publishState": {
"isPublished": true,
"isAcceptingResponses": false
}
}
}
Apps Script
/**
* Stop a Google Form from accepting responses using its URL.
*/
function closeMyFormForAcceptingResponses() {
// Replace with the URL of your Google Form
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
try {
const form = FormApp.openByUrl(formUrl);
// This disables the form for accepting responses.
form.setAcceptingResponses(false);
Logger.log(`Form "${form.getTitle()}" closed for accepting responses successfully.`);
// Optional: Verify the state
if (form.isPublished()) {
Logger.log('Form is still published.');
}
if (!form.isAcceptingResponses()) {
Logger.log('Form is no longer accepting responses.');
}
} catch (error) {
Logger.log(`Error unpublishing form: ${error}`);
}
}
Python
Node.js
양식이 기존 양식인지 확인
기존 양식은 publishSettings 필드가 없는 양식이지만 새로 만든 모든 양식은 게시 설정을 지원합니다.
양식이 게시를 지원하는지 확인하여 양식이 기존 양식인지 여부를 확인합니다. 이 메서드는 setPublished(enabled)
및 isPublished()
메서드와 응답자 권한이 사용 설정되어 있는지 확인하는 데 사용됩니다.
Apps Script
/**
* Checks if a form supports advanced responder permissions (i.e., is not a legacy form).
*/
function `checkIfFormSupportsPublishing()` {
// TODO(developer): Replace the URL with your own.
const formUrl = 'https://docs.google.com/forms/d/YOUR_FORM_ID/edit';
try {
const form = FormApp.openByUrl(formUrl);
// Checks whether the form supports publishing or not and logs it to the console.
const supportsPublishing = form.supportsAdvancedResponderPermissions();
if (supportsPublishing) {
Logger.log(`Form "${form.getTitle()}" supports publishing (not a legacy
form).`);
} else {
Logger.log(`Form "${form.getTitle()}" is a legacy form (does not support
publishing).`);
}
return supportsPublishing;
} catch (error) {
Logger.log(`Error unpublishing form: ${error}`);
}
}
Python
Node.js