![](/img/trans.png)
[英]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.