Интеграция Google DRIVE API используя service account в Application Express (apex+javascript)
Я новичок в апексе и полный нуб в программировании на javascript. Поставил задачу сделать интеграцию Google Drive API в апекс приложение. Аутентификация через service account, чтобы обеспечить доступ к файлам разным людям (через key-file)
Нашел на просторах интернета, вроде бы рабочий пример, на javascript, но проект выполнен в Node.js. Поэтому на этапе подключения библиотек начались пляски с бубном. Вот сорс сайт: https://medium.com/@bretcameron/how-to-use-the-google-drive-api-with-javascript-57a6cc9e5262
Рассматриваю пока только первую часть (создание аутентификации), подключение к Google Disk и отображение файлов которые там есть (которые расшарены с сервисным аккаунтом).
Напоминаю, что пишу не в Node.js а просто загружаю код в апекс, как сторонние библиотеки.
Вот мой файл: (gapi2.js) #####################################
const { google } = require(['https://apis.google.com/js/api.js']);
const scopes = ['https://www.googleapis.com/auth/drive'];
const credentials = require(['#APP_IMAGES#credentials.json']);
const auth = new google.auth.JWT(
credentials.client_email, null,
credentials.private_key, scopes
);
const drive = google.drive({ version: "v3", auth });
drive.files.list({}, (err, res) => {
if (err) throw err;
const files = res.data.files;
if (files.length) {
files.map((file) => {
console.log(file);
});
} else {
console.log('No files found');
}
});
#####################################
Ошибка при запуске:
gapi2.js:6 Uncaught TypeError: Cannot read property 'auth' of undefined
at gapi2.js:6
Refused to execute script from 'https://apex.oracle.com/pls/apex/f?p=4550:1:13365023955065:::::#APP_IMAGES#credentials.json.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
require.js:168
Uncaught Error: Script error for "#APP_IMAGES#credentials.json"
https://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1738)
Также пробовал явную подстановку client_email и private_key но ошибка (cannot read property 'auth' of undefined) сохраняется.
require подключено как внешняя библиотека. Код взят отсюда: https://requirejs.org/docs/download.html#requirejs (require.js 2.3.6)
JSON key file стандартного вида, сгенерен через google development console:
#########################
{
"type": "service_account",
"project_id": "XXXXXXXXXXX",
"private_key_id": "XXXXXXXXXXX",
"private_key": "-----BEGIN PRIVATE KEY-----bla bla bla-----END PRIVATE KEY-----\n",
"client_email": "XXXXXXXXXXX.gserviceaccount.com",
"client_id": "XXXXXXXXXXX",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/XXXXXXXXXXX.gserviceaccount.com"
Буду признателен любой помощи.