-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle.js
More file actions
42 lines (32 loc) · 990 Bytes
/
Copy pathgoogle.js
File metadata and controls
42 lines (32 loc) · 990 Bytes
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
const {google: googleapis} = require('googleapis');
const Google = function(google = googleapis) {
var self = this;
const auth = new google.auth.GoogleAuth({
// Scopes can be specified either as an array or as a single, space-delimited string.
scopes: ['https://www.googleapis.com/auth/spreadsheets.readonly']
});
this.init = async function() {
self.oauth2Client = await auth.getClient();
this.sheets = google.sheets({
version: 'v4',
auth: self.oauth2Client,
});
};
};
/**
* Fetch a list of data spreadsheets
*
*/
Google.prototype.getSheetData = async function(sheetID, range) {
try {
let response = await this.sheets.spreadsheets.values.get({
spreadsheetId: sheetID,
range: range
});
console.log('... data read in');
return response.data.values;
} catch (e) {
throw(e);
}
};
module.exports = Google;