nodejsからAPI経由でSpreadsheetを触る
サンプルのSpreadsheetはここから
クレデンシャルの入手
適当にプロジェクトを作ると良い
ライブラリのインストール
code:bash
$ yarn add googleapis google-auth-library
コード
code:typescript
import * as google from 'googleapis';
import { GoogleAuth } from 'google-auth-library';
async function main() {
const keyFile = 'path to json file';
const auth = new GoogleAuth({
keyFile,
scopes,
});
const client = await auth.getClient();
const sheets = new google.sheets_v4.Sheets({
auth: client,
});
const ret = await sheets.spreadsheets.values.get({
spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',
range: 'Class Data!A2:E',
})
console.log(ret);
}
main();