@Wynell_ru

Node.JS, Пытаюсь получить токен от Google API — как починить ошибку invalid_grant?

Вот код
const { google } = require('googleapis')
  , yaml = require('yamljs')
  , inquirer = require('inquirer')
  , open = require('open');

const credentials = yaml.load('./credentials.yml').web;

const auth = new google.auth.OAuth2({
  clientId: credentials.client_id,
  clientSecret: credentials.client_secret,
  redirectUri: credentials.redirect_uris[0]
});
async function main() {
  let URL = auth.generateAuthUrl({
    access_type: 'offline',
    scope: [
      'https://www.googleapis.com/auth/forms',
    ]
  });
  let { in_browser } = await inquirer.prompt({
    type: 'confirm',
    name: 'in_browser',
    message: 'Open the URL in browser?'
  });
  if (in_browser) open(URL);
  else console.log(`Open this URL to authorize this script: ${URL}`);
  let { code } = await inquirer.prompt({
    type: 'input',
    name: 'code',
    message: 'Enter the code you got now:'
  });
  let token = await auth.getToken(code);
  console.log(token);
}

main();
  • Вопрос задан
  • 101 просмотр
Решения вопроса 1
Prynik
@Prynik
Похожая ситуация тут
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы