Bu sayfada, formlarla ilgili aşağıdaki görevlerin nasıl yapılacağı açıklanmaktadır:
- Katılımcıların erişebilmesi için formu yayınlayın.
- Formunuza yanıt verenleri bulma
- Formunuzu daha fazla katılımcıyla paylaşma
- Formunuzdan yanıtlayanları kaldırma
- Formun "Bağlantıya sahip olan herkes"ten yanıt alıp almadığını kontrol edin.
- Formu kapatma
- Formu yayından kaldırma
- Forma yanıt kabul etmeyi durdurma
- Formun eski bir form olup olmadığını kontrol etme
Başlamadan önce
Bu sayfadaki görevlere devam etmeden önce aşağıdaki görevleri tamamlayın:
Form kimliğini alın. Form kimliği,
forms.create
kullanarak form oluşturduğunuzda yanıttakiformId
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 gövdesi
{
"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
Formunuza yanıt verenleri bulma
Form.getPublishedReaders() kullanarak katılımcı erişimine (PUBLISHED_READER rolü) sahip tüm kullanıcıların listesini alabilirsiniz. Bu işlem, kullanıcı nesnelerinin bir dizisini döndürür.
REST
Sorgu parametresi includePermissionsForView=published
'yı 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
Katılımcıları forma ekleyerek formu açıp yanıtlayabilmeleri için Drive permissions.create
yöntemini kullanabilirsiniz.
Form kimliği ve erişim ayarlarıyla
permissions.create
yöntemini çağırın.
REST
Örnek istek gövdesi
{
"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
Formunuzdan yanıtlayanları kaldırma
Yanıt verenleri e-posta adreslerine göre veya User nesnesi kullanarak kaldırabilirsiniz. Yanıtlayanı kaldırdığınızda, alan adı paylaşımı veya ortak drive erişimi gibi başka yollarla erişimi yoksa formu görüntüleme ve gönderme yetkisi iptal edilir.
Tek bir yanıtlayanı 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 listeleme" yoluyla 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 alıp almadığını kontrol edin.
Formun, bağlantıya sahip olan herkesten yanıt alıp almadığını 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"in forma yanıt verebilmesini 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 forma yanıt verebilir" ayarını 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 formu yayından kaldırmak için Forms.setPublished(false) yöntemini kullanırsınız. {/apps-script/reference/forms/form#setpublishedenabled} Formun yayından kaldırılması, formun kullanılamaz hale gelmesine ve otomatik olarak yanıt kabul etmeyi durdurmasına neden olur.
REST
Örnek istek gövdesi
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.
Formunuza yanıt verenler, kapatılan form sayfasını ve mesajını görür.
REST
Örnek istek gövdesi
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
Formun eski bir form olup olmadığını kontrol etme
Eski formlar, publishSettings alanı olmayan formlardır. Yeni oluşturulan tüm formlar ise yayın ayarlarını destekler.
Formun yayınlamayı destekleyip desteklemediğini belirleyerek formun 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