Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

google-auth-token-generator

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-auth-token-generator

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

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
222
decreased by-2.2%
Maintainers
1
Weekly downloads
 
Created
Source

Image from Gyazo

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の生成が出来ます。
    1. oAuthClientの生成関数のモジュールとして利用できます。

1. token.jsonの生成

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

2. oAuthClientの生成モジュール

読み込みます。googleapisも追加でインストールしましょう。

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

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

const auth = oAuth2ClientGen({
    library: google,
    CREDENTIALS_PATH: `credentials.json`, // optional
    TOKEN_PATH: 'token.json'; // optional
});
Google Spread SheetsのAPI利用サンプル
'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.
    1. run npx google-auth-token-generator
    1. A token.json file will be generated.

Keywords

FAQs

Package last updated on 03 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc