简体   繁体   English

我正在尝试从足球 api 请求信息,但我在回复时遇到了问题

[英]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.

相关问题 我在服务或部署Firebase托管功能时遇到了麻烦 - Im having trouble while serving or deploying Firebase Hosting Functions 我正在尝试使用 MongoDB 和 JWT 更新用户信息 - Im trying to update a users information using MongoDB and JWT 当我尝试在另一台电脑上运行 Cors 请求时没有成功 - Cors request did not succeed when im trying to run it on another pc 即时通讯找不到404 API - im getting 404 api not found 我是使用 node.js 制作 discord 机器人的新手,我遇到了错误问题,它说第 14 行和第 18 行中没有定义消息 - im new to making discord bots with node.js, i am having trouble with an error, it says that message is not defined in line 14 and 18 我正在尝试使用 Express 的 Sequelize 发布请求更新我的 SQL 数据库 - Im trying to update my SQL data base with a Sequelize post request with express 我正在尝试测试 node.js - Im trying to test out node.js 我试图将 mysql 与 nodejs 连接但有错误 - im trying to connect mysql with nodejs but have error 我在尝试使用 clarifai api 时遇到此错误,我该如何解决? - Im getting this error trying to use the clarifai api, how can i fix it? 我试图从 puppeteer(异步)向 mysql 插入数据,但我得到“connection.query 不是函数” - im trying to insert data to mysql from puppeteer (async) but I getting "connection.query is not a function"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM