如何使用Dialogflow V2查询修复身份验证错误

时间:2019-06-18 14:38:41

标签: angular typescript http dialogflow

我想从Angular应用程序查询Dialogflow V2,但是Authentication标头似乎不起作用。

运行此代码时,我总是收到错误代码401:

readonly baseURL: string = "https://dialogflow.googleapis.com/v2/projects/myprojectname/agent/sessions/12345:detectIntent";

readonly token = environment.dialogflow.token;

constructor(private http: HttpClient) {}

talk(query: string) {
    let body = {
      "queryInput": {
        "text": {
          "text": query,
          "languageCode": "en"
        }
      }
    }


    this.http.post(this.baseURL, body, {headers: {'Authorization': `Bearer 
     ${this.token}`}}).subscribe(
      res => {
        return console.log(res);
      }
    );
  }

我做错了什么?

1 个答案:

答案 0 :(得分:0)

现在我自己弄清楚了:我使用的是Dialogflow v1中的令牌,因此当然不起作用。