Bu sayfada, formlarla ilgili aşağıdaki görevlerin nasıl gerçekleştirileceği açıklanmaktadır:
- Katılımcıların erişebilmesi için formu yayınlayın
- Formunuza yanıt verecek kullanıcı bulma
- Formunuzu daha fazla katılımcıyla paylaşma
- Yanıtlayanları formunuzdan kaldırma
- Formun "Bağlantıya sahip olan herkes"ten yanıt kabul edip etmediğini kontrol edin.
- Formu kapatma
- Formu yayından kaldırma
- Form yanıtlarını kabul etmeyi durdurma
- Bir formun eski bir form olup olmadığını kontrol etme
Başlamadan önce
Bu sayfadaki görevlere devam etmeden önce aşağıdaki görevleri yapın:
Form kimliğini alın.
forms.create
kullanarak form oluşturduğunuzda form kimliği, yanıtınformId
alanında döndürülür.
Katılımcıların erişebilmesi için formu yayınlayın
Mevcut bir formu forms.setPublishSettings
yöntemiyle yayınlayabilirsiniz.
Form kimliğiyle
forms.setPublishSettings
yöntemini çağırın.
REST
Örnek istek metni
{
"publishSettings": {
"isPublished": true,
"isAcceptingResponses": true
}
}
Apps Komut Dosyası
/**
* 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
Formunuzu yanıtlayanları bulma
Form.getPublishedReaders() işlevini kullanarak katılımcı erişimi olan tüm kullanıcıların listesini (PUBLISHED_READER rolü) alabilirsiniz. Bu işlev, bir kullanıcı nesnesi dizisi döndürür.
REST
Sorgu parametresi includePermissionsForView=published
'ü istek URL'sine ekleyin.
Apps Komut Dosyası
/**
* 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
Formunuzu daha fazla katılımcıyla paylaşma
Formu açıp yanıtlayabilecek katılımcılar eklemek için Drive permissions.create
yöntemini kullanabilirsiniz.
Form kimliğini ve erişim ayarlarını kullanarak
permissions.create
yöntemini çağırın.
REST
Örnek istek metni
{
"view": "published",
"role": "reader",
"type": "user",
"emailAddress": "user@example.com"
}
Apps Komut Dosyası
/**
* 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
Yanıtlayanları formunuzdan kaldırma
E-posta adreslerine göre veya Kullanıcı nesnesini kullanarak yanıt verenleri tek tek kaldırabilirsiniz. Bir katılımcıyı kaldırdığınızda, alan paylaşımı veya ortak Drive erişimi gibi başka yollarla erişimi olmadığı sürece katılımcının formu görüntüleme ve gönderme yetkisi iptal edilir.
Tek bir katılımcıyı e-posta adresine göre kaldırma
REST
DELETE https://www.googleapis.com/drive/v3/files/{fileId}/permissions/PERMISSION
permissionID, daha önce açıklandığı gibi "yanıt verenleri listeleyerek" bulunabilir.
Apps Komut Dosyası
/**
* 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
Formun "Bağlantıya sahip olan herkes"ten yanıt kabul edip etmediğini kontrol edin.
Formun, bağlantıya sahip olan herkesten yanıt kabul edip etmediğini kontrol etmek için Drive Gelişmiş Hizmeti'ni etkinleştirmeniz gerekir.
- Drive Gelişmiş Hizmeti'ni etkinleştirin:
- Apps Komut Dosyası projenizi açın.
- Hizmetler'i (Hizmet'in yanındaki artı simgesi) tıklayın.
- Drive API'yi bulup Ekle'yi tıklayın.
- Ekle'yi tıklayın.
Apps Komut Dosyası
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
"Bağlantıya sahip olan herkes" seçeneğini belirleyerek formu yanıtlayabilecek kullanıcıları ayarlamak için:
Apps Komut Dosyası
function `setAnyoneWithLinkResponder`(formId) {
Drive.Permissions.create({
type: 'anyone',
view: 'published',
role: 'reader',
}, formId);
}
Python
Node.js
"Bağlantıya sahip olan herkes" seçeneğini kaldırmak için:
Apps Komut Dosyası
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
Formu kapatma
Bir formun yayınını kaldırmak için Forms.setPublished(false) yöntemini kullanırsınız. {/apps-script/reference/forms/form#setpublishedenabled} Bir formun yayından kaldırılması, formun kullanılamamasına neden olur ve yanıt kabul etmesini otomatik olarak durdurur.
REST
Örnek istek metni
POST https://forms.googleapis.com/v1/forms/{formId}:setPublishSettings
{
"publishSettings": {
"publishState": {
"isPublished": false
}
}
}
Apps Komut Dosyası
/**
* 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
Bir formun yayınını kaldırmadan yanıt kabul etmeyi durdurmak için Form.setAcceptingResponses(false)
yöntemini kullanabilirsiniz.
Formunuzu yanıtlayan kullanıcılar kapalı form sayfasını ve mesajı görür.
REST
Örnek istek metni
POST https://forms.googleapis.com/v1/forms/{formId}:setPublishSettings
{
"publishSettings": {
"publishState": {
"isPublished": true,
"isAcceptingResponses": false
}
}
}
Apps Komut Dosyası
/**
* 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
Bir formun eski bir form olup olmadığını kontrol etme
Eski formlar, publishSettings alanı içermeyen formlardır. Yeni oluşturulan tüm formlar ise yayınlama ayarlarını destekler.
Bir formun yayınlamayı destekleyip desteklemediğini belirleyerek eski olup olmadığını kontrol edin. Bu yöntem, setPublished(enabled)
ve isPublished()
yöntemlerinin ve yanıtlayıcı izinlerinin etkin olup olmadığını belirlemek için kullanılır.
Apps Komut Dosyası
/**
* 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