Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/max-keviv/googlesheetapi_tutorial
Google Sheet Api use
https://github.com/max-keviv/googlesheetapi_tutorial
Last synced: about 2 months ago
JSON representation
Google Sheet Api use
- Host: GitHub
- URL: https://github.com/max-keviv/googlesheetapi_tutorial
- Owner: max-keviv
- Created: 2021-05-02T05:41:37.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-19T06:54:54.000Z (about 3 years ago)
- Last Synced: 2023-03-09T23:55:45.087Z (almost 2 years ago)
- Language: EJS
- Homepage: https://googlesheetapi-tutorial.herokuapp.com/
- Size: 101 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
GoogleSheetAPI_TUTORIAL
```
const scopes = ['https://www.googleapis.com/auth/spreadsheets'];
// Create an JWT client to authorize the API call
const client = new google.auth.JWT(
keys.client_email,
null,
keys.private_key,
scopes,
);client.authorize((err, tokens) => {
if (err) {
console.log(err);
} else {
console.log('connected');
}
});async function gsrun(client) {
const gsapi = google.sheets({ version: 'v4', auth: client });
const opt = {
spreadsheetId: '10gvHUWTPJ9-omNXBsFHvNn65xYTfJYNRoSm1efNOe4k',
range: 'A2:B5',
};const data = await gsapi.spreadsheets.values.get(opt);
const records = data.data.values;
return records;
}async function gsadd(client, newData) {
const gsapi = google.sheets({ version: 'v4', auth: client });const updateOptions = {
spreadsheetId: '10gvHUWTPJ9-omNXBsFHvNn65xYTfJYNRoSm1efNOe4k',
range: 'A:B',
valueInputOption: 'USER_ENTERED',
resource: { values: newData },
};
const res = await gsapi.spreadsheets.values.append(updateOptions);
console.log(res);
}/* To get data from Google Sheet use function gsrun(client) */
app.get('/../..', async (req, res) => {
records = await gsrun(client);
console.log(records);
res.render('task2-partA', { items: records });
});/* To Add data to Google Sheet use function gsadd(client) */
app.post('/.../.../...', async (req, res) => {
const data = [[req.body.add_name, req.body.add_link]];
await gsadd(client, data);});
```