HttpErrorResponse : ionic 3 & dialogflow


#1

I’m using dialog flow in ionic 3.I’m trying to send and get response through http request. This is my home.ts file code.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Message } from '../module/message.module';
import { ChatProvider } from '../../providers/chat/chat';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  messages: Message[] = [];

  constructor(public navCtrl: NavController,private chatprovider: ChatProvider) {

  }

  // ionViewDidLoad(){
  //   let message = new Message("hi")
  //   this.messages.push(message);
  // }

  sendMesage(message_content) {
    this.chatprovider.sendMessage(message_content.value).subscribe(res =>{
      console.log(res);
      // let message = new Message(res.result.speech);
      // this.messages.push(message);
      // message_content.value = '';
    }, err => {
      console.log(err)
    }
    )
  }
}

this is my chatprovider.ts file code

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

@Injectable()
export class ChatProvider {

  url = 'https://api.dialogflow.com/v1/query';
  accessToken = 'xxxxxxxxxxxxxxxxxxxxxxxx';

  constructor(public http: HttpClient) {
    console.log('Hello ChatProvider Provider');
  }

  sendMessage(message: string) {
    let data = {
      lang: "en",
      query: message
    }
    let headers = new HttpHeaders();
    headers.append("Authorization","Bearer" + this.accessToken);
    return this.http.post(this.url, data,{headers: headers})
          .map(res => {
            return res
          })
  }

}

This is the error I’m facing

polyfills.js:3 POST https://api.dialogflow.com/v1/query 403 (

HttpErrorResponse {headers: HttpHeaders, status: 403, statusText: “OK”, url: “https://api.dialogflow.com/v1/query”, ok: false, …}error: {status: {…}}headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}message: "Http failure response for https://api.dialogflow.com/v1/query: 403 OK"name: "HttpErrorResponse"ok: falsestatus: 403statusText: "OK"url: "https://api.dialogflow.com/v1/query"proto: HttpResponseBase