Moving Google Alerts from Gmail account to Google storage to be scraped for keywords. Script appears to run, then get error message "CloudStorage Not Defined". Can't get past it. Looked at all APis to be enabled that have to do with storage. Got a Service Account with credentials all that stuff. Got a Project Name, Project ID and Project #.
Hi @69Letchworth,
Welcome to Google Cloud Community!
The "CloudStorage Not Defined" error usually means that your script doesn't recognize the CloudStorage object. This might be because the required library isn't imported, the Google Cloud Storage API isn't turned on, or there might be an issue with authentication. Also, your “CloudStorage” object might be referring to a bucket storage, your bucket may have not been created. Here are some steps to help you resolve your error:
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.
Think I hit the wrong reply button:
Thank you for this. I think I have most of this covered. Where do I insert
the GOOGLE APPLICATION CREDENTIALS. I've got the JSON file and have
inserted but no luck with running it. If I may, I'd like to share what I ve
done so far and get your feedback. Gemini and ChatGPT aren't solving my
problems yet.
function saveGoogleAlertsToCloudStorage() {
// 1. Access Gmail and find Google Alert emails
var threads = GmailApp.search('label:Google Alerts1'); // Use your actual
label
for (var i = 0; i < threads.length; i++) {
var messages = threads[i].getMessages();
for (var j = 0; j < messages.length; j++) {
var message = messages[j];
// 2. Extract data from the email
var subject = message.getSubject();
var body = message.getBody();
// (Use regular expressions or other methods to extract specific data
like links, titles, etc.)
// 3. Prepare the data for Cloud Storage (e.g., as a JSON string)
var data = JSON.stringify({
subject: subject,
body: body,
//... other extracted data
});
// 4. Upload to Google Cloud Storage
var bucketName = 'new-bucket030525'; // Replace with your bucket name
var fileName = 'alert_22125' + message.getId() + '22125.json'; //
Unique filename
SpreadsheetApp.getActiveSpreadsheet().toast('Saving alert to Cloud
Storage: ' + fileName);
saveToCloudStorage(bucketName, fileName, data);
}
}
}
function saveToCloudStorage(bucketName, fileName, data) {
// Get the Cloud Storage service and bucket
var bucket = DriveApp.getStorageFolder(bucketName);
// Create a new blob (file) in the bucket
var blob = bucket.createFile(fileName, data, MimeType.JSON);
}
--
[image: Email Signature Button (2).jpg]
<>
John Krisulewicz
Data Analyst, DonorSearch
(PII Removed by Staff)
(URL Removed by Staff)
Have not heard back from Joy_S regarding my questions. -John