我已经创建了Dialogflow V2代理,并试图将其与ionic 4 App集成。
已执行的步骤:
- 创建了一个服务帐户,并通过Google控制台创建了JSON密钥文件。
- 将路径添加到ENV变量GOOGLE_APPLICATION_CREDENTIALS
- 还运行以下命令进行gcloud身份验证
- gcloud auth应用程序-默认登录名
- gcloud auth应用程序-默认打印访问令牌
- 我什至可以使用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);
}));
回复:
在此响应中,数据以字符串形式返回。我尝试解析数据,如果我使用 response.data.queryResult或Response.queryResult,则显示未定义。 感谢和问候, 贾纳尼