# google-auth-token-generator

> [![Image from Gyazo](https://i.gyazo.com/92b73b1253594a5c39761079492cb9da.gif)](https://gyazo.com/92b73b1253594a5c39761079492cb9da)

Latest version **0.2.0** (published 2022-04-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install google-auth-token-generator
pnpm add google-auth-token-generator
yarn add google-auth-token-generator
bun add google-auth-token-generator
```

Provides the command `google-auth-token-generator`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2022-04-11 |
| First published | 2021-02-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | n0bisuke |
| Maintainers | n0bisuke |
| Keywords | Google, Youtube, Google Drive, Gmail, Google Sheets |

## Links

- npm: https://www.npmjs.com/package/google-auth-token-generator
- Repository: https://github.com/n0bisuke/google-auth-token-generator
- Homepage: https://github.com/n0bisuke/google-auth-token-generator#readme
- Issues: https://github.com/n0bisuke/google-auth-token-generator/issues
- npm.io page: https://npm.io/package/google-auth-token-generator

## Dependencies (2)

- [inquirer](https://npm.io/package/inquirer.md) ^7.3.3
- [googleapis](https://npm.io/package/googleapis.md) ^100.0.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2022-04-11
- 0.1.4 — 2021-05-03
- 0.1.3 — 2021-05-03
- 0.1.2 — 2021-05-03
- 0.1.1 — 2021-05-03
- 0.1.0 — 2021-05-03
- 0.0.13 — 2021-05-03
- 0.0.12 — 2021-05-03
- 0.0.11 — 2021-04-21
- 0.0.10 — 2021-04-21
- 0.0.9 — 2021-04-21
- 0.0.8 — 2021-04-21
- 0.0.7 — 2021-02-22
- 0.0.6 — 2021-02-22
- 0.0.5 — 2021-02-22
- … 4 more at https://npm.io/package/google-auth-token-generator/versions

## README

[![Image from Gyazo](https://i.gyazo.com/92b73b1253594a5c39761079492cb9da.gif)](https://gyazo.com/92b73b1253594a5c39761079492cb9da)

## google-auth-token-generator

Gooogle系APIのtoken.jsonを取得するためのCLIツールです。
npx経由で実行すればインストール不要です。

* Google Drive
* Gmail
* Google Calender
* Youtube Data API
* Google Sheets

に対応しています。(2021/5/3時点)

## 使い方

* 1. CLIツールとして、token.jsonの生成が出来ます。
* 2. oAuthClientの生成関数のモジュールとして利用できます。

### 1. token.jsonの生成 

* 1. Googleのサイトから利用したいAPIの`credentials.json`を取得します。
* 2. `npx google-auth-token-generator`を実行します。
* 3. `token.json`が生成されます

### 2. oAuthClientの生成モジュール

読み込みます。[googleapis](https://github.com/googleapis/google-api-nodejs-client)も追加でインストールしましょう。

```js
const {google} = require('googleapis');
const {oAuth2ClientGen} = require('google-auth-token-generator');
```

利用する際は以下のように読み込みます。
ファイル名は任意に変更できますがcredentials.jsonとtoken.jsonがデフォルトです。

```js
const auth = oAuth2ClientGen({
  library: google,
  /*ファイル利用の場合*/
  CREDENTIALS_PATH: `credentials.json`, // optional
  TOKEN_PATH: 'token.json'; // optional
});
```

また、環境変数などを利用したい場合はCREDENTIALSとTOKENのキーにセットして下さい。ファイル読み込みはしません。

```js
const auth = oAuth2ClientGen({
  library: google,
  /*環境変数利用の場合*/
  CREDENTIALS: process.env.GOOGLE_CREDENTIAL, //optional
  TOKEN: process.env.GOOGLE_TOKEN,  //optional
});
```

#### Google Spread SheetsのAPI利用サンプル

```js
'use strict';

const {google} = require('googleapis');
const {oAuth2ClientGen} = require('google-auth-token-generator');

(async () => {
    const auth = oAuth2ClientGen({library: google});
    const sheets = google.sheets({version: 'v4', auth});

    try {
        const res = await sheets.spreadsheets.values.get({
            spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',
            range: 'Class Data!A2:E',
        });

        const rows = res.data.values;
        if (rows.length) {
          console.log('Name, Major:');
          // Print columns A and E, which correspond to indices 0 and 4.
          rows.map((row) => {
            console.log(`${row[0]}, ${row[4]}`);
          });
        } else {
          console.log('No data found.');
        }

    } catch (error) {
        console.log('The API returned an error: ' + error);
    }
})();
```

## how to use

* 1. Get `credentials.json` first from the Google API site.
* 2. run `npx google-auth-token-generator`
* 3. A `token.json` file will be generated.

---
_Source: https://npm.io/package/google-auth-token-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
