小编pee*_*lte的帖子

使用NodeJS在Heroku上验证Google Sheet API

我按照此示例访问Google表格API:

https://developers.google.com/sheets/api/quickstart/nodejs

在示例代码中,以下方法用于获取新的oauth令牌.

function getNewToken(oauth2Client, callback) {
  var authUrl = oauth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: SCOPES
  });
  console.log('Authorize this app by visiting this url: ', authUrl);
  var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });
  rl.question('Enter the code from that page here: ', function(code) {
    rl.close();
    oauth2Client.getToken(code, function(err, token) {
      if (err) {
        console.log('Error while trying to retrieve access token', err);
        return;
      }
      oauth2Client.credentials = token;
      storeToken(token);
      callback(oauth2Client);
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

这在我的本地计算机上工作正常(在终端中按提示手动访问页面,并在命令行中输入代码).但这似乎不切实际,并不适用于Heroku.有没有办法自动化这个?也许通过在nodeJS应用程序中获取URL(和令牌)并以某种方式存储它?

提前致谢.

google-api heroku google-docs-api node.js google-oauth

4
推荐指数
1
解决办法
1763
查看次数