joesaunderson/sportmonks-soccer

PHP的简单SportMonks足球API客户端

v0.6 2022-01-21 22:12 UTC

README

Build Status

PHP库,用于Sportmonks足球API。由Joe Saunderson开发。

先决条件

PHP >= 7.3

安装

composer require joesaunderson/sportmonks-soccer

设置

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();

许可

MIT