-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.js
47 lines (36 loc) · 1.09 KB
/
google.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const {google} = require('googleapis');
const util = require('util')
const Google = function() {
var self = this;
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/spreadsheets']
});
this.init = async function() {
self.oauth2Client = await auth.getClient();
this.sheets = google.sheets({
version: 'v4',
auth: self.oauth2Client,
});
};
};
/**
* Append a list of data to a spreadsheet
*/
Google.prototype.postRowData = async function(sheetID, row_data) {
try {
let response = await this.sheets.spreadsheets.values.append({
spreadsheetId: process.env.GOOGLE_SHEET_ID,
range: process.env.GOOGLE_SHEET_RANGE,
valueInputOption: 'RAW',
insertDataOption: 'INSERT_ROWS',
resource: {
values: [ row_data ]
}
});
return response.data.values;
} catch (e) {
console.log('ERROR :: Google API rejected : ' + e);
throw(e);
}
}
module.exports = Google;