首页 > 解决方案 > 使用 node.js 为开发人员设置 Google 表格,在允许我的 API 查看我的电子表格后,它重定向到“找不到页面”

问题描述

我正在尝试让Google Sheets API与 node 一起使用,并且到目前为止,它要求我使用我的 Google 帐户对其进行签名,并允许该应用程序查看我的 Google 电子表格。在我按下允许后,它会将我重定向到找不到显示“ERR_CONNECTION_REFUSED”的页面。在 URL 中,它显示为“code=4”,但我找不到它代表什么。我目前被困在控制台中,等待此页面的代码。等待代码.

我的代码与 API 文档中的代码完全相同,但我不得不将“credentials.installed”更改为“credentials”,否则它不起作用。

这可能与我的回调 URI 有关吗?我将“授权的 JavaScript 来源”和授权的重定向 URI 都作为“http://localhost:8080”。

我的 credentials.JSON 看起来像这样

{
"client_id":"XXXX",
"project_id":"XXXX","auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"XXXX",
"redirect_uris":["http://localhost:8080"],
"javascript_origins":["http://localhost:8080"]

}

总而言之:在我按下“接受”按钮后,我得到一个“找不到页面”而不是您应该粘贴到控制台的代码。

标签: google-sheetsgoogle-sheets-api

解决方案


我选择了“Web 应用程序”而不是“桌面应用程序”。只需从快速启动下载凭证 JSON 并直接复制代码即可。我的错。


推荐阅读