-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle.js
More file actions
44 lines (42 loc) · 1.14 KB
/
google.js
File metadata and controls
44 lines (42 loc) · 1.14 KB
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
'use strict';
var https = require('https');
var google = require('googleapis');
var key = require('./key.json');
var utils = require('./utils.js');
var SHEET_ID = '1YB8T1_lQSjO2Jxec4gctdPVgDq0ndxaNCJ6DHe7Pu3A';
function getdata(cb) {
var store = '';
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key, ['https://www.googleapis.com/auth/spreadsheets.readonly'],
null
);
jwtClient.authorize((err, tokens) => {
if (err) {
console.log(err);
return;
}
var opts = {
hostname: 'sheets.googleapis.com',
port: 443,
path: `/v4/spreadsheets/${SHEET_ID}/values/Sheet1!A2:D6`,
method: 'GET',
headers: {
'Authorization': `Bearer ${tokens.access_token}`
}
};
var req = https.request(opts, function(res) {
res.on('data', (chunk) => {
store = store + chunk
});
res.on('end', () => {
cb(store)
});
});
req.end();
});
}
module.exports = {
getdata: getdata
}