![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
google-auth-token-generator
Advanced tools
[![Image from Gyazo](https://i.gyazo.com/92b73b1253594a5c39761079492cb9da.gif)](https://gyazo.com/92b73b1253594a5c39761079492cb9da)
Gooogle系APIのtoken.jsonを取得するためのCLIツールです。 npx経由で実行すればインストール不要です。
に対応しています。(2021/5/3時点)
credentials.json
を取得します。npx google-auth-token-generator
を実行します。token.json
が生成されます読み込みます。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
});
また、環境変数などを利用したい場合はCREDENTIALSとTOKENのキーにセットして下さい。ファイル読み込みはしません。
const auth = oAuth2ClientGen({
library: google,
/*環境変数利用の場合*/
CREDENTIALS: process.env.GOOGLE_CREDENTIAL, //optional
TOKEN: process.env.GOOGLE_TOKEN, //optional
});
'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);
}
})();
credentials.json
first from the Google API site.npx google-auth-token-generator
token.json
file will be generated.FAQs
[![Image from Gyazo](https://i.gyazo.com/92b73b1253594a5c39761079492cb9da.gif)](https://gyazo.com/92b73b1253594a5c39761079492cb9da)
We found that google-auth-token-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.