igorlealantunes / sportmonks-soccer-api
PHP 的简单 SportMonks 足球 API 客户端
dev-master
2023-11-21 21:24 UTC
Requires
- php: ^7.3 | ^8.2
- symfony/http-client: ^5.4
This package is auto-updated.
Last update: 2024-09-21 22:57:43 UTC
README
PHP 库,用于 Sportmonks 足球 API。由 Joe Saunderson 开发。
先决条件
PHP >= 7.4
安装
composer require igorlealantunes/sportmonks-soccer-api
设置
API 客户端依赖于环境变量进行配置(设置 API 令牌和时区)。
安装
composer require symfony/dotenv
用法
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
示例 .env 文件
# API TOKEN (Required) # https://sportmonks.com/settings#/api SPORTMONKS_API_TOKEN=_YOUR_API_TOKEN_HERE # TIMEZONE (Optional) # https://sportmonks.com/docs/football/2.0/getting-started/a/setting-the-timezone/82 SPORTMONKS_TIMEZONE=Europe/London
用法
use Sportmonks\Soccer\SoccerApi; ... // Basic API call for all Bookmakers $response = SoccerApi::bookmakers()->getAll();
分页、过滤、排序和数据丰富
Sportmonks API 允许进行高级过滤和排序,以及通过关系添加数据。此客户端支持以下功能:
包含
// API call for Fixtures with includes $response = SoccerApi::fixtures() ->setIncludes(['goals', 'flatOdds:filter(bookmaker_id|2)']) ->getByDate('2019-05-28');
分页
// API call for Fixtures with page specified $response = SoccerApi::fixtures() ->setPage(3) ->getByDate('2019-05-28');
注意:分页元数据($response['meta']['pagination']
)可用于遍历页面并构建结果集。
额外参数
某些端点允许将数据作为 URI 查询参数传递,如下所示,必须在 ->get..() 调用之前添加。
->setBookmakers([1, 2]) ->setFixtures([1, 2]) ->setLeagues([1, 2]) ->setMarkets([1, 2])
注意:此客户端不会验证正确端点的使用,也不会抛出错误。请参阅 Sportmonks 文档 了解哪些端点支持上述参数。
完整端点示例
博彩公司
获取所有 - 查看 Sportmonks 文档
$response = SoccerApi::bookmakers()->getAll();
通过 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::bookmakers()->getById($bookmakerId);
教练
通过 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::coaches()->getById($coachId);
评论
通过比赛 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::commentaries()->getByFixtureId($fixtureId);
大陆
获取所有 - 查看 Sportmonks 文档
$response = SoccerApi::continents()->getAll();
通过 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::continents()->getById($continentId);
国家
获取所有 - 查看 Sportmonks 文档
$response = SoccerApi::countries()->getAll();
通过 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::countries()->getById($countryId);
比赛
通过 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::fixtures()->getById($fixtureId);
通过日期获取 - 查看 Sportmonks 文档
$response = SoccerApi::fixtures()->getByDate($date);
通过日期范围获取 - 查看 Sportmonks 文档
$response = SoccerApi::fixtures()->getByDateRange($dateFrom, $dateTo);
通过团队日期范围获取 - 查看 Sportmonks 文档
$response = SoccerApi::fixtures()->getByDateRangeForTeam($dateFrom, $dateTo, $teamId);
通过多个 ID 获取 - 查看 Sportmonks 文档
$response = SoccerApi::fixtures()->getByMultipleIds([$fixtureId1, $fixtureId2...]);
获取最后更新 - 查看Sportmonks文档
$response = SoccerApi::fixtures()->getLastUpdated();
交锋记录
通过团队ID获取 - 查看Sportmonks文档
$response = SoccerApi::head2head()->getByTeamIds($team1Id, $team2Id);
联赛
获取所有 - 查看Sportmonks文档
$response = SoccerApi::leagues()->getAll();
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::leagues()->getById($legueId);
实时比分
获取所有 - 查看Sportmonks文档
$response = SoccerApi::liveScores()->getAll();
获取所有进行中 - 查看Sportmonks文档
$response = SoccerApi::liveScores()->getAllInPlay();
市场
获取所有 - 查看Sportmonks文档
$response = SoccerApi::markets()->getAll();
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::markets()->getById($marketId);
赔率
通过比赛和博彩公司获取 - 查看Sportmonks文档
$response = SoccerApi::odds()->getByFixtureAndBookmaker($fixtureId, $bookmakerId);
通过比赛和市场获取 - 查看Sportmonks文档
$response = SoccerApi::odds()->getByFixtureAndMarket($fixtureId, $marketId);
通过比赛ID获取 - 查看Sportmonks文档
$response = SoccerApi::odds()->getByFixtureId($fixtureId);
通过比赛ID获取进行中赔率 - 查看Sportmonks文档
$response = SoccerApi::odds()->getInPlayByFixtureId($fixtureId);
球员
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::players()->getById($playerId);
预测
获取联赛表现 - 查看Sportmonks文档
$response = SoccerApi::predictions()->getLeagues()
获取概率 - 查看Sportmonks文档
$response = SoccerApi::predictions()->getProbabilities()
通过比赛ID获取概率 - 查看Sportmonks文档
$response = SoccerApi::predictions()->getProbabilitiesByFixtureId($fixtureId)
获取价值投注 - 查看Sportmonks文档
$response = SoccerApi::predictions()->getValueBets()
通过比赛ID获取价值投注 - 查看Sportmonks文档
$response = SoccerApi::predictions()->getValueBetsByFixtureId($fixtureId)
轮次
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::rounds()->getById($roundId);
通过赛季ID获取 - 查看Sportmonks文档
$response = SoccerApi::rounds()->getBySeasonId($seasonId);
赛季
获取所有 - 查看Sportmonks文档
$response = SoccerApi::seasons()->getAll();
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::seasons()->getById($seasonId);
阶段
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::stages()->getById($stageId);
通过赛季ID获取 - 查看Sportmonks文档
$response = SoccerApi::stages()->getBySeasonId($seasonId);
积分榜
通过赛季ID获取 - 查看Sportmonks文档
$response = SoccerApi::standings()->getBySeasonId($seasonId);
获取实时积分榜 - 查看Sportmonks文档
$response = SoccerApi::standings()->getLiveStandingsBySeasonId($seasonId);
队伍
通过ID获取 - 查看Sportmonks文档
$response = SoccerApi::teams()->getById($teamId);
通过赛季获取 - 查看Sportmonks文档
$response = SoccerApi::teams()->getBySeasonId($seasonId);
队伍阵容
按球队和赛季获取 - 查看Sportmonks文档
$response = SoccerApi::teamSquads()->getByTeamAndSeason($teamId, $seasonId);
得分王
按赛季ID获取 - 查看Sportmonks文档
$response = SoccerApi::topScorers()->getBySeasonId($seasonId);
按赛季ID聚合 - 查看Sportmonks文档
$response = SoccerApi::topScorers()->getAggregatedBySeasonId($seasonId);
电视台
按比赛ID获取 - 查看Sportmonks文档
$response = SoccerApi::tvStations()->getByFixtureId($fixtureId);
场地
按ID获取 - 查看Sportmonks文档
$response = SoccerApi::venues()->getById($venueId);
按赛季ID获取 - 查看Sportmonks文档
$response = SoccerApi::venues()->getBySeasonId($seasonId);
视频精华
按比赛ID获取 - 查看Sportmonks文档
$response = SoccerApi::videoHighlights()->getAll();