[英]Im having trouble while serving or deploying Firebase Hosting Functions
[英]Im trying to request information from an football api but Im having trouble with the responses
所以我試圖從 football-data.org api 請求信息,但我遇到了麻煩,因為它返回黑色信息我試着查看文檔,但沒有用於 Nodejs 的信息
這是我的代碼
import express from 'express';
import 'dotenv/config';
import fetch from 'node-fetch';
const app = express();
app.set('view engine', 'ejs');
app.use(express.static("public"));
app.get("/", function(req, res){
fetch("https://api.football-data.org/v2/competitions/PL/matches?status=SCHEDULED", {
headers: {
method: 'GET',
'X-Auth-Token': process.env.API_KEY,
},
})
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.error(err));
});
app.listen(3000, function(){
console.log("Server has started on port 3000");
});
當我運行它時,我用不同的數字得到了大約 20 次
{
id: 327024,
season: [Object],
utcDate: '2022-04-23T14:00:00Z',
status: 'SCHEDULED',
matchday: 34,
stage: 'REGULAR_SEASON',
group: null,
lastUpdated: '2021-06-16T14:31:53Z',
odds: [Object],
score: [Object],
homeTeam: [Object],
awayTeam: [Object],
referees: []
},
我應該得到類似的東西
球隊的名字和其他不是 object 的東西
假設您的 API 密鑰是正確的,您只需將您的competition
更改為 GET URL 中的competitions
。
請參閱下面的工作鏈接,我可以在生成 API 密鑰后嘗試使用 Postman。
https://api.football-data.org/v2/competitions/PL/matches?status=SCHEDULED
將您當前的 URL 替換為這個,它應該可以工作(除非您的 API 密鑰有問題)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.