如何在Ionic App中使用Dialogflow Api.ai V2

我已经创建了Dialogflow V2代理,并试图将其与ionic 4 App集成。

已执行的步骤

  1. 创建了一个服务帐户,并通过Google控制台创建了JSON密钥文件。
  2. 将路径添加到ENV变量GOOGLE_APPLICATION_CREDENTIALS
  3. 还运行以下命令进行gcloud身份验证
    1. gcloud auth应用程序-默认登录名
    2. gcloud auth应用程序-默认打印访问令牌
  4. 我什至可以使用Google jwt令牌创建访问令牌

这里的问题是,当我在离子应用程序甚至邮递员中使用相同的访问令牌时,会收到 401未经授权的无效访问令牌错误

我已经按照下面的链接创建了Ionic App https://www.yuribacciarini.com/integrate-dialogflow-chatbot-on-ionic-app/

API呼叫:

我正在使用本机HTTP调用

import { HTTP } from '@ionic-native/http/ngx';

 private nativeHttp: HTTP

let encUrl = "https://dialogflow.googleapis.com/v2/projects/id/agent/sessions/id:detectIntent";

  return from(this.nativeHttp.post("URL",data,headers)
        .then(res => {   
          console.log(res); //Returning [object object]
           console.log(JSON.stringify(res)); //Returning data as single string
          return res;
        },(error: any) => {
          return this.handleError(error);
        }));

回复:

如何在Ionic App中使用Dialogflow Api.ai V2

在此响应中,数据以字符串形式返回。我尝试解析数据,如果我使用 response.data.queryResult或Response.queryResult,则显示未定义。 感谢和问候, 贾纳尼

iCMS 回答:如何在Ionic App中使用Dialogflow Api.ai V2

您关注的博客已过期。

要与dialogflow API通信,您需要具有访问令牌。

您可以遵循API v2指南,

https://chatbotslife.com/dialogflow-v2-rest-api-communication-6cf7ab66ab36

本文链接:https://www.f2er.com/1862156.html

大家都在问