Estoy llamando a la API HTTPS desde el servicio Angular implementado en el servidor http mediante el siguiente código.
this.chatbotUrl = "https://something.com/api"; getDashBoardData(): Observable<any> { return this.http.get<IContainer>(this.chatbotUrl+"/chatbot/get-dashboard-data").pipe( map((response) => (response ? response : {})), catchError( this.handleError ) ); }Pero cuando llamo a esta API, recibo este error, "Respuesta de falla de HTTP para https://something.com/api/chatbot/get-dashboard-data : 0 Error desconocido". También se obtiene el siguiente error.
GET https://something.com/api/chatbot/get-time-wise-traffic/7 net::ERR_CERT_COMMON_NAME_INVALID¿Cómo puedo llamar a la API https desde el servicio Angular implementado en el servidor http?
Supongo que no ha configurado la API correctamente, verifique si el sitio requiere alguna clave para acceder. Aquí proporcioné el archivo component.ts y el archivo de servicio para la API con la que estoy trabajando para su referencia. Si hay un error de CORS, intente agregar la extensión CORS a su navegador; de lo contrario, borre su caché y ejecute su código nuevamente.
Componente.ts:
import { Component, OnInit } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; import { YoutubeService } from '../youtube.service'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'] }) export class HomeComponent implements OnInit { Name:any; details: any; info:any; display!:boolean; constructor(private service:YoutubeService,public sanitizer: DomSanitizer) { } ngOnInit(): void { this.service.GetVideos().subscribe((res:any)=> { this.info= res as any this.info=this.info.items; console.log(this.info); this.display=true }); } onSubmit() { this.service.GetSearch(this.Name).subscribe(res=> { this.details= res as any this.details=this.details.items; // this.details.forEach((function.this.details.i) => { // ele // }); console.log(this.details); this.display=true }); } }Servicio:
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { GoogleLoginProvider } from 'angularx-social-login'; @Injectable({ providedIn: 'root' }) export class YoutubeService { private APIURL = "https://youtube.googleapis.com/youtube/v3/"; private APIKEY ="AIzaSyB40HaKwd0VggftBq8R9sEwQx_NG5xOOWc"; constructor(private http:HttpClient) { } public GetSearch(name:string) { console.log(name) return this.http.get(this.APIURL+"search?part=snippet&key="+this.APIKEY+"&q="+name+"&type=video"); }