UNPKG

gmail-getter

Version:

A simple tool that gets emails from the Gmail API

36 lines (35 loc) 1.54 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const local_auth_1 = require("@google-cloud/local-auth"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const script = async () => { const CREDENTIALS_PATH = path_1.default.join(process.cwd(), 'credentials.json'); const SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']; console.log("Starting the process of obtaining a refresh token... \ \nINFO: This script is processing information from 'credentials.json' in your current folder."); if (!fs_1.default.existsSync(CREDENTIALS_PATH)) { console.error(`credentials.json not found in ${process.cwd()} \nPlease place credentials.json in the current directory`); return; } let client; try { client = await (0, local_auth_1.authenticate)({ scopes: SCOPES, keyfilePath: CREDENTIALS_PATH }); } catch (e) { throw new Error(`Authentication request has failed.\n${JSON.stringify(e, null, 2)}`); } if (!client.credentials) { throw new Error('Failed to obtain credentials - unknown error.'); } if (!client.credentials.refresh_token) { throw new Error('Failed to obtain refresh token - unknown error.'); } console.log(client.credentials.refresh_token); }; script().catch(e => console.error(e));