-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (59 loc) · 1.58 KB
/
index.js
File metadata and controls
87 lines (59 loc) · 1.58 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const express = require('express');
const {
google
} = require('googleapis');
const app = express();
app.set('view engine', 'ejs');
app.use(express.urlencoded({
extended: true
}));
app.get('/', (req, res) => {
res.render('index');
})
app.post('/', async (req, res) => {
const {
nick,
code,
team,
location,
phone,
email
} = req.body;
const auth = new google.auth.GoogleAuth({
keyFile: 'credentials.json',
scopes: 'https://www.googleapis.com/auth/spreadsheets',
});
// create clinete instance auth
const client = await auth.getClient();
// instance of google sheets API
const googleSheets = google.sheets({
version: 'v4',
auth: client
});
const spreadsheetId = '11NqWwCvuONUB_bjN3QlisupRCDSKFS7bT8RkbIADA7M';
// get metadata about the spreadsheet
const metaData = await googleSheets.spreadsheets.get({
auth,
spreadsheetId,
});
// read rows from spreadsheets
const getRows = await googleSheets.spreadsheets.values.get({
auth,
spreadsheetId,
range: 'Respuestas',
});
// write rows to spreadsheets
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: 'Respuestas',
valueInputOption: 'USER_ENTERED',
resource: {
values: [
[nick, code, team, location, phone, email]
],
},
});
res.send('Successfully sent');
});
app.listen(1337, (req, res) => console.log('running on port 1337'));