I have created a Dialogflow V2 agent and am trying to integrate the same with ionic 4 App.
Steps Followed:
- Created a service account and created a JSON key file from google console.
- Added the path to ENV variables GOOGLE_APPLICATION_CREDENTIALS
- Also ran the below commands for gcloud authentication
- gcloud auth application-default login
- gcloud auth application-default print-access-token
- I can even able to create the access token using the google jwt token
Here the problem is when I use the same access token in my ionic app or even in the postman, am getting 401 unauthorized Invalid access token error.
I have followed the below link to create the Ionic App https://www.yuribacciarini.com/integrate-dialogflow-chatbot-on-ionic-app/
API CALL:
I am using Native HTTP call
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:
In this response data returned as string. I have tried to parse the data and if I take response.data.queryResult or Response.queryResult it shows undefined. Thanks & Regards, Janani