Coingecko api 404 angular get request



我正试图从硬币壁虎api中提取数据,但我得到404错误状态,并且body返回错误:"Collection 'v3' not found"我使用的api url是https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd.

我正在使用Angular并使用https。get请求。

这是我的服务类

const httpOptions = {
headers: new HttpHeaders({
'Content-Type':  'application/json',
Authorization: 'my-auth-token'
})
};
constructor(private http: HttpClient) { }
api: string = 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd';
getCoinData(): Observable<Coin[]> {
return this.http.get<Coin[]>(this.api, httpOptions);
}

这是我的组件文件

constructor(private cryptoCoinService : CryptoCoinsService) { }
ngOnInit(): void {
this.getTopCoins();
}
getTopCoins() {
this.cryptoCoinService.getCoinData()
.subscribe(data => {
this.topCoins = data;
},
err => console.log(err));
}

应该返回

{
"bitcoin": {
"usd": 17274.17
}
}

感谢您的回复。我弄清楚了,我忘了我是使用InMemoryDataService从早些时候,当我测试一些东西,我只需要注释那些部分出来。

最新更新