feat: use proper credenetials path
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
import { google } from "googleapis";
|
import { google } from "googleapis";
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import logger from "../../logger";
|
||||||
|
|
||||||
export async function writeDataToSheet(spreadsheetId: string, range: string, data: any[]) {
|
export async function writeDataToSheet(spreadsheetId: string, range: string, data: any[]) {
|
||||||
try {
|
try {
|
||||||
const credentialsPath = path.join(__dirname, 'service_account_credentials.json');
|
const integrationCredentialsPath = path.join(__dirname, 'integrations.json');
|
||||||
const credentials = JSON.parse(fs.readFileSync(credentialsPath, 'utf-8'));
|
const integrationCredentials = JSON.parse(fs.readFileSync(integrationCredentialsPath, 'utf-8'));
|
||||||
|
|
||||||
const auth = new google.auth.GoogleAuth({
|
const auth = new google.auth.GoogleAuth({
|
||||||
credentials: {
|
credentials: {
|
||||||
client_email: credentials.client_email,
|
client_email: integrationCredentials.credentials.client_email,
|
||||||
private_key: credentials.private_key,
|
private_key: integrationCredentials.credentials.private_key,
|
||||||
},
|
},
|
||||||
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
|
scopes: ['https://www.googleapis.com/auth/spreadsheets'],
|
||||||
});
|
});
|
||||||
@@ -27,9 +28,9 @@ export async function writeDataToSheet(spreadsheetId: string, range: string, dat
|
|||||||
requestBody: resource,
|
requestBody: resource,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Data written to Google Sheet: ${spreadsheetId}, Range: ${range}`);
|
logger.log(`info`, `Data written to Google Sheet: ${spreadsheetId}, Range: ${range}`);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(`Error writing data to Google Sheet: ${error.message}`);
|
logger.log(`error`, `Error writing data to Google Sheet: ${error.message}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user