无法读取未定义的属性'client_secret'

问题描述 投票:8回答:5

我尝试使用Node.js创建一个示例程序,遵循https://developers.google.com/google-apps/activity/v1/quickstart/nodejs的指示

我抛出一个错误,说在尝试运行时无法读取未定义的属性“client_secret”。

寻找您宝贵的建议。

提前致谢。

node.js google-drive-sdk
5个回答
5
投票

var clientSecret = credentials.installed.client_secret;在此行中,凭据指向client_secret.json,因此必须“安装”第一个密钥。在我的情况下,密钥是“web”,这导致错误。我刚刚将关键“web”重命名为“已安装”。


3
投票

enter image description here

看来你错过了Step 1: Turn on the Google Apps Activity API

创建凭据后:

F。单击客户端ID右侧的file_download(下载JSON)按钮。

G。将此文件移动到您的工作目录并将其重命名为client_secret.json。把它放在你的项目文件夹中。


0
投票

您的client_secret.json文件需要包含以下行:

"redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]

而不是如下所示的行:

"javascript_origins":
    [
      "http://localhost:8080",
      "http://localhost:1453",
      "http://127.0.0.1:1453",
      "http://localhost"
    ]

此外,您可能想要将client_secret.json中的链头从web更改为installed,反之亦然。


0
投票

我有这个问题,但我有错误的凭证类型文件。我最初使用“Web服务器(Nodejs)...”,它有“web”标题而不是“已安装”,但是当我再次执行它并选择“Windows UI(cmd line)”时,我得到了文件格式正确。


0
投票

由于没有名为“已安装”的密钥,因此将其解析为undefined

credentials.json中,将关键“web”更改为“已安装”。可能文档需要从Google的方面改变。

之前

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.