admin管理员组文章数量:1122832
I am trying to save user emails with subscribe button on a webapp made through Google Apps Script with access to anyone. This webapp has a email form where user enter their email and post request is made from the button. I want to know if the Google Sheet containing all the emails can be accessed by other users in any way. I want to ensure that the sheet remains private and that no one else can view the emails stored in it.
Below is my doPost()
code:
function doPost(e) {
try {
const spreadsheet = SpreadsheetApp.openById("asbasdsdf...");
const sheet = spreadsheet.getSheetByName("Subscriptions");
// Check if the sheet exists
if (!sheet) {
throw new Error(`The sheet "${sheetName}" does not exist.`);
}
// Parse JSON payload
const data = JSON.parse(e.postData.contents);
const email = data.email;
// Check if the email already exists in the specified column
const range = sheet.getRange(1, column, sheet.getLastRow(), 1);
const existingEmails = range.getValues().flat();
if (existingEmails.includes(email)) {
return ContentService.createTextOutput(
JSON.stringify({ status: "error", message: "This email is already subscribed for " + bookCover })
).setMimeType(ContentService.MimeType.JSON);
}
// Format current date and time (DD/MM/YYYY, HH:MM:SS)
const timestamp = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd/MM/yyyy, HH:mm:ss");
// Append email and timestamp
const row = sheet.getLastRow() + 1;
sheet.getRange(row, column).setValue(email);
sheet.getRange(row, 3).setValue(timestamp);
// Success response
return ContentService.createTextOutput(
JSON.stringify({ status: "success", message: "Email saved successfully!" })
).setMimeType(ContentService.MimeType.JSON);
} catch (error) {
return ContentService.createTextOutput(
JSON.stringify({ status: "error", message: error.message })
).setMimeType(ContentService.MimeType.JSON);
}
}
本文标签:
版权声明:本文标题:If I use a Google Site along with an Apps Script webapp(set to 'Anyone' access)linked to a Google Sheet, is the 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736400360a1944315.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论