From 8e1951ba67ba4fe3b85633eb903ddd35ed18aa75 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 25 Dec 2020 15:15:51 -0500 Subject: [PATCH] Access google files with Service Account Using API key is triggering "automation" warnings from Google --- server/googleActions.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/googleActions.js b/server/googleActions.js index 2173c4e55..1fc93a861 100644 --- a/server/googleActions.js +++ b/server/googleActions.js @@ -257,7 +257,14 @@ GoogleActions = { throw ('Share ID does not match'); } - const file = await drive.files.get({ + //Access actual file with service account. Just api key is causing "automated query" errors. + const keys = JSON.parse(config.get('service_account')); + const serviceAuth = google.auth.fromJSON(keys); + serviceAuth.scopes = ['https://www.googleapis.com/auth/drive']; + + const serviceDrive = google.drive({ version: 'v3', auth: serviceAuth }); + + const file = await serviceDrive.files.get({ fileId : id, fields : 'description, properties', alt : 'media'