我无法为我的 angular 聊天机器人应用程序的迁移指南中提供的 Dialogflow V2 实施身份验证设置?

I am unable to implement authentication setup for Dialogflow V2 provided in migration guide for my angular chat bot app?

我正在将使用 DialogFlow API V1 及其查询功能与我的机器人聊天的 angular 应用程序迁移到 Dialog Flow API v2 及其相应的 detectIntent 方法。但是我在官方文档 here 提供的实施身份验证步骤中遇到了问题。 我遵循了文档的所有步骤,当我 运行 命令

时,我能够看到我的令牌的值
gcloud auth application-default print-access-token 

在我的 Google 云 SDK shell.

问题是这样的: 当前 angular 应用发送带有 header 格式的 http 请求:

let headers = new HttpHeaders({
      'Authorization': "Bearer " + this.token,
      'Content-Type': 'application/json'
    });

其中 this.token 是我的 API v1 令牌。我不知道把这段代码改成我想要的:

let headers = new HttpHeaders({
      'Authorization': "Bearer " + `$(gcloud auth application-default print-access-token),`,
      'Content-Type': 'application/json'
    });

如何在我的 angular 应用程序中实现这一目标。

注:

  1. 通过在 Google 提供的 "Try this API" 功能中提供我的查询,我成功地获得了 detectIntnent 方法的响应。这意味着我对 POST 请求有正确的 body,我只需要正确的 Header.

除此之外,我还有一个后续问题。如果这看起来微不足道,我深表歉意,因为我是 Angular 和对话流程的新手:

  1. 我将 angular 应用推送到 heroku。 V2 中引入的此服务帐户身份验证是否意味着我还需要在我的 heroku 实例中安装 Google Cloud。

我检查了 SO Angular 服务身份验证功能的实现,但我找不到它。

我能够在 Dialog Flow 的 V2 版本中实现身份验证。基本上我对如何实现它感到困惑。但是在做一些研究时我发现我需要制作一个后端应用程序并使用对话流包来处理查询。 Google 提供了节点js samplecode 来实现v2 版本的对话流。 这段代码帮助我制作了一个后端来使用 detectIntent 方法处理查询。