[英]Im trying to request information from an football api but Im having trouble with the responses
So Im trying to request information from the football-data.org api but Im having trouble because its returning black information i tried looking at the documentation but there's none for Nodejs所以我试图从 football-data.org api 请求信息,但我遇到了麻烦,因为它返回黑色信息我试着查看文档,但没有用于 Nodejs 的信息
Here is my code这是我的代码
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");
});
when i run it i get this about 20 times just with different numbers当我运行它时,我用不同的数字得到了大约 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: []
},
i should get something like我应该得到类似的东西
the names off the teams playing and the other stuff not object球队的名字和其他不是 object 的东西
Assuming your API key is correct you just need to change your competition
to competitions
in your GET URL.假设您的 API 密钥是正确的,您只需将您的competition
更改为 GET URL 中的competitions
。
See a working link below that I was able to try on Postman after generating my API key.请参阅下面的工作链接,我可以在生成 API 密钥后尝试使用 Postman。
https://api.football-data.org/v2/competitions/PL/matches?status=SCHEDULED
Replace your current URL with this one and it should work (unless something is wrong with your API key).将您当前的 URL 替换为这个,它应该可以工作(除非您的 API 密钥有问题)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.