Hi support,
My goal is to write a custom code script for a Google Sheet in Apps Script that auto-retrieves (ie. via Trigger) a csv that I have stored in my Google Cloud Storage bucket. My preference is to complete this daily automated task with the csv file marked as private, for security purposes, and if possible, to use OAuth to complete the internal retrieval of the csv data and to parse it to a spreadsheet – with the csv file to be updated with new data on a recurring basis.
Since I’m relatively new to the Google Cloud space, with basic but limited understanding of Apps Script JSON-based coding knowledge/skill, I found this article (dated in 2021) which has the custom code instructions detailed already:
https://h-p.medium.com/google-cloud-csv-to-google-sheets-740243e04f3a
The coder/author of the article mentions at the end that this is a good way to keep the data process internal, and going through OAuth keeps it even out of the service account (again, better security protocols/best practice). As a result, I tried implementing the sample code provided in the above article for testing purposes.
I’m trying to run a test with the provided code script in the above article as the base and so far, after following per the steps described – whenever I run the test in Apps Script – I have gotten to where the popup screen asks to authenticate the OAuth creds for the Web Application, and then after I approve it, the Execution log results in the following:
11:17:01 AM Notice Execution started
11:17:01 AM Info Sign in - Google Accounts{followed by a long string here}
11:17:02 AM Notice Execution completed
When I check the Logging results in GCP, it doesn’t show many further details, just that the web application script was called with the google api – but none of the other ‘logging’ sections from the code script are to be found in the logs.
As a result, I don’t understand where to troubleshoot further. It is unclear to me whether the issue is from the OAuth creds not going through – although other users in forums have indicated that if OAuth is not working properly, it would result in an error – and it doesn’t appear that my test run results in an error. At least, it doesn’t say ‘error’ anywhere in the Execution Log in Apps Script, nor in the GCP Cloud Logging log. I can see that the linked Google sheet is actually clearing/sizing the range that I have specified in the Apps Script, but no data from the csv in my Google Bucket is being written into the sheet. I’ve checked, and re-checked all my IAM permissions – and even talked with a Google Support agent via chat, and he said all the permissions looked good from what he could tell – and then he recommended that I post a request on here in the Community forum to ask to any feedback.
I’ve even added permissions for the OAuth email address (and service account) into my Google Workpace admin. I’ve gone through each line of the code, and also studied the resources that are linked per the above article. I’ve also tried modifying the code extensively, based upon either the github instructions – and also other users who have reported trying similar tests, but the same issue has persisted.
I’ve tried adding all appropriate scopes into the ‘apsscript.json’ header of the Apps Script extension of the linked Google sheet - the same issue persists, with the same Execution Log in Apps Script. And after the initial pop-up screen where I had at first authenticated the Web Application, now that no longer appears (unless I make significant alterations to the Apps Script code – then on occasion I may get the pop-up again requesting OAuth authentication – but if I approve it, the same Execution Log is the result, with no data displaying in the spreadsheet).
So – it’s unclear to me – is there an OAuth issue here? And if there is, then why is there no OAuth error message in either the Execution Log or Cloud Logging log? Or, is there an issue with identifying or finding the csv file in the Google Bucket? I’ve tripled checked all my detailed credential and links including the bucket name, file name (ie. the bucket object), Script ID and the right URI added to OAuth, I’ve made sure the Google Cloud project ID is added to the Apps Script, the OAuth 2 library is added, the Google Drive and Google Storage APIs are added, the APIs have been enabled in GCP, etc.
I wonder if perhaps any API changes by Google – in the time since the article was written in 2021 – may have made this internal API retrieval discontinued. I would prefer to find a way to resolve the issue so the data parses and is displaying properly into the linked Google sheet, but if I’m unable to reproduce the test on my end, then I may have to look into going an alternate route.
If you have any feedback, please advise, and I would certainly appreciate any insights or suggestions.
Thanks,
TJ
