I want to communicate with the Dialogflow CX API from my React application. The relevant code looks like this:
componentWillMount() {
let payload = {
"queryInput": {
"text": {
"text": "Hi!"
},
"languageCode": "en"
},
"queryParams": {
"timeZone": "America/Los_Angeles"
}
}
axios.post('https://global-dialogflow.googleapis.com/v3/' + this.state.projectId + '/sessions/' + this.state.sessionId + ':detectIntent', payload)
.then(response => {
this.setState({ dialogResponse: response });
})
.catch(error => {
console.log(error)
})
console.log(this.state.dialogResponse)
}
However, the response is 401.
I have create a service account and downloaded the private key as a JSON file as per https://cloud.google.com/docs/authentication/.
How do I then use this to authenticate my API call?