【发布时间】:2018-01-27 05:08:03
【问题描述】:
我正在学习如何使用 Google Sheets API v.4 从工作表下载数据 --> 我的 nodeJS 服务器。我正在为我的节点应用程序使用 Docker 容器。在 Docker 中的本地主机或在线服务器上失败。它可以在 localhost 上正常工作,但不能在 Docker 容器中工作。我已在 Google API 控制台上将 IP 地址列入白名单。 (注意:我可以轻松地从这个节点服务器使用 firebase API,而不是 Google Sheets v4 API)
参考:https://developers.google.com/sheets/api/quickstart/nodejs#step_4_run_the_sample
第一次运行应用程序时,节点服务器上的命令行显示:
Authorize this app by visiting this url:
https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets.readonly&response_type=code&client_id=xxx.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob
您转到该 URL,然后显示该 Google 页面:
Sign in
Please copy this code, switch to your application and paste it there.
4/xxxxxxxxxxxx
这就是问题所在。那是行不通的。我可以将4/xxx 令牌复制并粘贴到命令行中,但它失败了。没有错误信息,什么都没有。也没有功能。有没有办法从这里到达那里?我知道这在我的台式计算机上的独立节点服务器中可以正常工作,但在 docker 容器(本地主机或在线)中不行。是否有手动认证方法?
-----------编辑----------------------------------- ----------------------
我再次开始查看代码,问题是使用 docker 容器时节点 readline 失败。
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
而且 StackOveflow 上已经存在这个问题。
Unable to get standard input inside docker container
重复:
how to get docker container to read from stdin?
您需要使用 --interactive 以交互模式运行容器 或 -i:
哇...您如何在 docker-compose 部署中做到这一点?
Interactive shell using Docker Compose
哎哟。不要继续那个帖子。对我一点用都没有。请参阅下面提供的答案...
此处提供信息,以防其他人在路上遇到这种情况。
【问题讨论】:
-
关于“手动验证方法”,您要手动检索刷新令牌吗?如果我误解了你的问题,我很抱歉。
-
查看我的更新。此问题与how to get docker container to read from stdin? 重复。
-
很抱歉,由于我的英语水平不佳,耽搁了您的时间。
-
田池..没问题。你的笔记让我重新思考我的方法并再次仔细查看代码。我还在做这个..我一直无法通过终端输入内容..仍在测试。我的目的是在弄清楚发生了什么后更新这个问题。
-
感谢您的好意。
标签: node.js docker docker-compose google-oauth google-sheets-api