Я использую диалоговое окно в ionic 3. Я пытаюсь отправить и получить ответ через http-запрос.Это мой код файла home.ts.
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)
}
)
}
}
Это мой код файла chatprovider.ts
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
})
}
}
Это ошибка, с которой я сталкиваюсь
polyfills.js: 3 POST https://api.dialogflow.com/v1/query 403 () s @ polyfills.js: 3 t.scheduleTask @ polyfills.js: 3 onScheduleTask @ polyfills.js: 3 t.scheduleTask @ polyfills.js: 3 r.scheduleTask @ polyfills.js: 3 r.scheduleMacroTask @ polyfills.js: 3 (анонимный) @ polyfills.js: 3 o. (анонимная функция) @ polyfills.js: 2 (анонимный) @ http.js: 2364 Observable._trySubscribe@ Observable.js: 172 Observable.subscribe @ Observable.js: 160 subscribeToResult @ subscribeToResult.js: 23 MergeMapSubscriber._innerSub @ mergeMap.js: 132 MergeMapSubscriber._tryNext @ mergeMap.japs 112: mergeMap.japs_ 112.next @ Subscriber.js: 93 ScalarObservable._subscribe @ ScalarObservable.js: 49 Observable._trySubscribe @ Observable.js: 172 Observable.subscribe @ Observable.js: 160 MergeMapOperator.call @ mergeMap.js: 87 Observable.s.js: 157 фильтрOperator.call @ filter.js: 60 Observable.subscribe @ Observable.js: 157 MapOperator.call @ map.js: 56 Observable.subscribe @ Observable.js: 157 MapOperator.call @ map.js: 56 Observable.subscribe @ Observable.js: 157 webpackJsonp.197.HomePage.sendMesage @ home.ts: 23 (анонимно) @ HomePage.html: 24 handleEvent @ core.js: 13589 callWithDebugContext @ core.js: 15098 debugHandleEvent @ core.js: 14685 dispatchEvent @ core.js: 10004 (анонимный) @ core.js: 10629 (анонимный) @ platform-browser.js: 2628 t.invokeTask @ polyfills.js: 3 onInvokeTask @ core.js: 4751 t.invokeTask @ polyfills.js: 3 r.runTask @ polyfills.js: 3 e.invokeTask @ polyfills.js: 3 p @ polyfills.js: 2 v @ polyfills.js: 2 home.ts: 29