{"id":26499731,"url":"https://github.com/n0bisuke/google-auth-token-generator","last_synced_at":"2025-03-20T15:18:58.340Z","repository":{"id":43809362,"uuid":"341075789","full_name":"n0bisuke/google-auth-token-generator","owner":"n0bisuke","description":null,"archived":false,"fork":false,"pushed_at":"2022-04-11T06:49:16.000Z","size":18,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-18T23:03:43.047Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/n0bisuke.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-22T04:06:06.000Z","updated_at":"2022-11-17T22:56:40.000Z","dependencies_parsed_at":"2022-09-04T21:12:20.356Z","dependency_job_id":null,"html_url":"https://github.com/n0bisuke/google-auth-token-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0bisuke%2Fgoogle-auth-token-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0bisuke%2Fgoogle-auth-token-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0bisuke%2Fgoogle-auth-token-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/n0bisuke%2Fgoogle-auth-token-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/n0bisuke","download_url":"https://codeload.github.com/n0bisuke/google-auth-token-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244380217,"owners_count":20443574,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-20T15:18:57.811Z","updated_at":"2025-03-20T15:18:58.334Z","avatar_url":"https://github.com/n0bisuke.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Image from Gyazo](https://i.gyazo.com/92b73b1253594a5c39761079492cb9da.gif)](https://gyazo.com/92b73b1253594a5c39761079492cb9da)\n\n## google-auth-token-generator\n\nGooogle系APIのtoken.jsonを取得するためのCLIツールです。\nnpx経由で実行すればインストール不要です。\n\n* Google Drive\n* Gmail\n* Google Calender\n* Youtube Data API\n* Google Sheets\n\nに対応しています。(2021/5/3時点)\n\n## 使い方\n\n* 1. CLIツールとして、token.jsonの生成が出来ます。\n* 2. oAuthClientの生成関数のモジュールとして利用できます。\n\n### 1. token.jsonの生成 \n\n* 1. Googleのサイトから利用したいAPIの`credentials.json`を取得します。\n* 2. `npx google-auth-token-generator`を実行します。\n* 3. `token.json`が生成されます\n\n### 2. oAuthClientの生成モジュール\n\n読み込みます。[googleapis](https://github.com/googleapis/google-api-nodejs-client)も追加でインストールしましょう。\n\n```js\nconst {google} = require('googleapis');\nconst {oAuth2ClientGen} = require('google-auth-token-generator');\n```\n\n利用する際は以下のように読み込みます。\nファイル名は任意に変更できますがcredentials.jsonとtoken.jsonがデフォルトです。\n\n```js\nconst auth = oAuth2ClientGen({\n  library: google,\n  /*ファイル利用の場合*/\n  CREDENTIALS_PATH: `credentials.json`, // optional\n  TOKEN_PATH: 'token.json'; // optional\n});\n```\n\nまた、環境変数などを利用したい場合はCREDENTIALSとTOKENのキーにセットして下さい。ファイル読み込みはしません。\n\n```js\nconst auth = oAuth2ClientGen({\n  library: google,\n  /*環境変数利用の場合*/\n  CREDENTIALS: process.env.GOOGLE_CREDENTIAL, //optional\n  TOKEN: process.env.GOOGLE_TOKEN,  //optional\n});\n```\n\n#### Google Spread SheetsのAPI利用サンプル\n\n```js\n'use strict';\n\nconst {google} = require('googleapis');\nconst {oAuth2ClientGen} = require('google-auth-token-generator');\n\n(async () =\u003e {\n    const auth = oAuth2ClientGen({library: google});\n    const sheets = google.sheets({version: 'v4', auth});\n\n    try {\n        const res = await sheets.spreadsheets.values.get({\n            spreadsheetId: '1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms',\n            range: 'Class Data!A2:E',\n        });\n\n        const rows = res.data.values;\n        if (rows.length) {\n          console.log('Name, Major:');\n          // Print columns A and E, which correspond to indices 0 and 4.\n          rows.map((row) =\u003e {\n            console.log(`${row[0]}, ${row[4]}`);\n          });\n        } else {\n          console.log('No data found.');\n        }\n\n    } catch (error) {\n        console.log('The API returned an error: ' + error);\n    }\n})();\n```\n\n## how to use\n\n* 1. Get `credentials.json` first from the Google API site.\n* 2. run `npx google-auth-token-generator`\n* 3. A `token.json` file will be generated.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn0bisuke%2Fgoogle-auth-token-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fn0bisuke%2Fgoogle-auth-token-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fn0bisuke%2Fgoogle-auth-token-generator/lists"}