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
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
{
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
Assuming your API key is correct you just need to change your competition
to competitions
in your GET URL.
See a working link below that I was able to try on Postman after generating my API key.
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.