PHP code example of corbpie / nbalive

1. Go to this page and download the library: Download corbpie/nbalive library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

corbpie / nbalive example snippets


$this->url;//The final compiled URL used in the call
$this->response_code;//Returned HTTP response code
$this->response_size;//The size of the response
$this->connect_time;//Time it took to connect
$this->ip;//The IP of the API endpoint that was connected to

$this::CURRENT_SEASON;//Returns current season
$this::PREVIOUS_SEASON;//Returns previous season
$this::CURRENT_TYPE;//Returns current season type

//Mode types
$this::MODE_PER_GAME;
$this::MODE_TOTAL;
$this::MODE_PER48;

//Game types
$this::TYPE_REGULAR;
$this::TYPE_PLAY_IN;
$this::TYPE_PLAYOFFS;
$this::TYPE_ALL_STAR;
$this::TYPE_PRE_SEASON;

$today = new NBALive\NBAToday();

//Creates the arrays
$today->all_games;
$today->live_games;
$today->upcoming_games;
$today->completed_games;

//Format this data
$formatted = $today->gameFormatter($today->live_games);

$game_time = new NBALive\NBABase();
$game_time->secondsToFormattedGameTime(800);

$boxscore = new NBALive\NBABoxScore('0022301214');

//Or set game id with
$boxscore->game_id = "0022301214";

//Creates the arrays
$boxscore->home_team;
$boxscore->away_team;

$boxscore->home_players;
$boxscore->away_players;

$boxscore->sortAsc($boxscore->home_players, 'points');
$boxscore->sortDesc($boxscore->home_players, 'points');

//Get inactive players for both teams
$boxscore->getInactive();

$pbp = new NBALive\NBAPlayByPlay('0022301214');

//Or set game id with
$pbp->game_id = "0022301214";

//Creates the arrays
$pbp->all_plays;
$pbp->plays_count;
$pbp->last_10_plays;

//Player only plays
$pbp->playerOnly(202331);

//Team only plays
$pbp->teamOnly(1610612746);

//Get a score line/worm
$pbp->scoreLine();

$game_id = '0022300372';
$start_qtr = 1;
$end_qtr = 1;

$pbp_v3 = new NBALive\NBAPlayByPlayV3($game_id, $start_qtr, $end_qtr);

//Creates the arrays
$pbp_v3->all_plays;
$pbp_v3->plays_count;
$pbp_v3->last_10_plays;

//Player only plays
$pbp_v3->playerOnly(202331);

//Team only plays
$pbp_v3->teamOnly(1610612746);

//Scored only plays
$pbp_v3->scoredOnly();

//Get a score streaks for both teams
$pbp_v3->scoreStreaks();

$game_id = '0022300372';
$start_qtr = 1;
$end_qtr = 1;

$pbp_v2 = new NBALive\NBAPlayByPlayV2($game_id, $start_qtr, $end_qtr);

//Creates the arrays
$pbp_v2->all_plays;
$pbp_v2->plays_count;
$pbp_v2->last_10_plays;

//Player only plays
$pbp_v2->playerOnly(202331);

//Team only plays
$pbp_v2->teamOnly(1610612746);

//Scored only plays
$pbp_v2->scoredOnly();


$game_id = '0022300372';
$start_qtr = 1;
$end_qtr = 1;

$pbp_v1 = new NBALive\NBAPlayByPlayV1($game_id, $start_qtr, $end_qtr);

//Creates the arrays
$pbp_v1->all_plays;
$pbp_v1->plays_count;
$pbp_v1->last_10_plays;

//Scored only plays
$pbp_v1->scoredOnly();


$game_id = '0022300372';
$event_number = 89;

$play_clip = new NBALive\NBAPlayByPlayClips($game_id, $event_number);

//Creates the arrays
$play_clip->media;
$play_clip->details;

$bs = new NBALive\NBABoxScoreTraditional();
//Whole game
$bs->game_id = '0022300372';
$bs->fetch();

//Use true to only get home and visit players arrays and return early
$bs->fetch(true);

//Preset filter (Qtr 4)
$bs->game_id = '0022300372';
$bs->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$bs->fetch();

//Custom filter
$bs->game_id = '0022300372';
$bs->range_type = 1;
$bs->start_period = 4;
$bs->start_range = 0;
$bs->end_range = 28800;
$bs->end_period = 4;
$bs->filter = $bs->build();
$bs->fetch();

//Creates the arrays
$bs->teams;
$bs->teams_starters;
$bs->teams_bench;

$bs->home_team;
$bs->home_players;
$bs->home_starters;
$bs->home_bench;

$bs->away_team;
$bs->away_players;
$bs->away_starters;
$bs->away_bench;

$bs->sortAsc($bs->home_players, 'fieldGoalsAttempted');
$bs->sortDesc($bs->home_players, 'fieldGoalsMade');

$defensive = new NBALive\NBABoxScoreDefensive("0022301203");

//Or set game id with
$defensive->game_id = "0022301203";

//Creates the arrays
$defensive->home_players;
$defensive->away_players;

$matchups = new NBALive\NBABoxScoreMatchups("0022301203");

//Or set game id with
$matchups->game_id = "0022301203";

//Creates the arrays
$matchups->home_players;
$matchups->away_players;

//Get just a certain players matchups
$matchups->playerOnly(1629684);

//Get all matchups for a player
$matchups->playerMatchedWith(201935);

$scoring = new NBALive\NBABoxScoreScoring();
//Whole game
$scoring->game_id = '0022300372';
$scoring->fetch();

//Preset filter (Qtr 4)
$scoring->game_id = '0022300372';
$scoring->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$scoring->fetch();

//Custom filter
$scoring->game_id = '0022300372';
$scoring->range_type = 1;
$scoring->start_period = 4;
$scoring->start_range = 0;
$scoring->end_range = 28800;
$scoring->end_period = 4;
$scoring->filter = $bs->build();
$scoring->fetch();

//Creates the arrays
$scoring->home_players;
$scoring->away_players;

$scoring->home_team;
$scoring->away_team;

$misc = new NBALive\NBABoxScoreMisc();
//Whole game
$misc->game_id = '0022300372';
$misc->fetch();

//Preset filter (Qtr 4)
$misc->game_id = '0022300372';
$misc->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$misc->fetch();

//Custom filter
$misc->game_id = '0022300372';
$misc->range_type = 1;
$misc->start_period = 4;
$misc->start_range = 0;
$misc->end_range = 28800;
$misc->end_period = 4;
$misc->filter = $bs->build();
$misc->fetch();

//Creates the arrays
$misc->home_players;
$misc->away_players;

$misc->home_team;
$misc->away_team;

$usage = new NBALive\NBABoxScoreUsage();
//Whole game
$usage->game_id = '0022300372';
$usage->fetch();

//Preset filter (Qtr 4)
$usage->game_id = '0022300372';
$usage->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$usage->fetch();

//Custom filter
$usage->game_id = '0022300372';
$usage->range_type = 1;
$usage->start_period = 4;
$usage->start_range = 0;
$usage->end_range = 28800;
$usage->end_period = 4;
$usage->filter = $bs->build();
$usage->fetch();

//Creates the arrays
$usage->home_players;
$usage->away_players;

$usage->home_team;
$usage->away_team;

$fourfactors = new NBALive\NBABoxScore4Factors("0022301203");
//Whole game
$fourfactors->game_id = '0022300372';
$fourfactors->fetch();

//Preset filter (Qtr 4)
$fourfactors->game_id = '0022300372';
$fourfactors->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$fourfactors->fetch();

//Custom filter
$fourfactors->game_id = '0022300372';
$fourfactors->range_type = 1;
$fourfactors->start_period = 4;
$fourfactors->start_range = 0;
$fourfactors->end_range = 28800;
$fourfactors->end_period = 4;
$fourfactors->filter = $bs->build();
$fourfactors->fetch();

//Creates the arrays
$fourfactors->home_players;
$fourfactors->away_players;

$fourfactors->home_team;
$fourfactors->away_team;

$adv = new NBALive\NBABoxScoreAdvanced();
//Whole game
$adv->game_id = '0022300372';
$adv->fetch();

//Preset filter (Qtr 4)
$adv->game_id = '0022300372';
$adv->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$adv->fetch();

//Custom filter
$adv->game_id = '0022300372';
$adv->range_type = 1;
$adv->start_period = 4;
$adv->start_range = 0;
$adv->end_range = 28800;
$adv->end_period = 4;
$adv->filter = $bs->build();
$adv->fetch();

//Creates the arrays
$adv->home_players;
$adv->away_players;

$adv->home_team;
$adv->away_team;

$tracking = new NBALive\NBABoxScoreTracking();
//Whole game
$tracking->game_id = '0022300372';
$tracking->fetch();

//Preset filter (Qtr 4)
$tracking->game_id = '0022300372';
$tracking->filter = $bs->buildQ4();//buildQ1(), buildQ2(), buildH1() etc.
$tracking->fetch();

//Custom filter
$tracking->game_id = '0022300372';
$tracking->range_type = 1;
$tracking->start_period = 4;
$tracking->start_range = 0;
$tracking->end_range = 28800;
$tracking->end_period = 4;
$tracking->filter = $bs->build();
$tracking->fetch();

//Creates the arrays
$tracking->home_players;
$tracking->away_players;

$tracking->home_team;
$tracking->away_team;

$lineups = new NBALive\NBATeamLineups();

$lineups->team_id = 1610612746;
$lineups->season = '2019-20';//Optional if NOT set will just be current season
$lineups->players_amount = 5;
$lineups->fetch();

//Creates the array
$lineups->details;

//Get lineups that contain a certain player only
$lineups->playerOnly(202695)

$team_shots = new NBALive\NBATeamDashPtShots();

$team_shots->team_id = 1610612746;
$team_shots->season = '2019-20';//Optional if NOT set will just be current season
$team_shots->fetch();

//Creates the arrays
$team_shots->general_shooting;
$team_shots->shot_clock_shooting;
$team_shots->dribble_shooting;
$team_shots->closest_defender_shooting;
$team_shots->closest_defender_10ft_shooting;
$team_shots->touch_time_shooting;

$rotations = new NBALive\NBARotations("0022301203");

//Or set game id with
$rotations->game_id = "0022301203";

//Creates the array
$pbp->details;

//Player only rotation
$pbp->playerOnly(202331);

//Team only rotation
$pbp->teamOnly(1610612746);

$team_yoy = new NBALive\NBATeamYearOverYear(1610612746);

//Creates the arrays
$team_yoy->details;
$team_yoy->latest;

$standings = new NBALive\NBAStandings('2023-24');

//Creates the arrays
$standings->standings;
$standings->east_standings;
$standings->west_standings;

$gl = new NBALive\NBALeagueGameLog();

//Creates the array
$gl->games;

$team = new NBALive\NBATeamInfo(1610612746);

//Creates the arrays
$team->info;
$team->ranks;
$team->seasons;

$logs = new NBALive\NBATeamGameLogs();
$logs->team_id = 1610612746;
$logs->season = '2023-24';//Optional
$logs->fetch();

//Creates the array
$logs->games;

//Last X games
$logs->lastXGames(10);//Last 10 games only

$players = new NBALive\NBAFranchisePlayers(1610612746);

//Creates the array
$players->players;

$schedule = new NBALive\NBASchedule('2023-12-20');

//Creates the array
$schedule->schedule;

//Get full season schedule for a team
$schedule->fullForTeam(1610612746);

//Get tomorrow's games
$tomorrow = (new DateTimeImmutable('tomorrow', new DateTimeZone('America/New_York')))->format('Y-m-d');

$schedule = new NBALive\NBASchedule($tomorrow);

//Get upcoming games for a team in next 7 days
$schedule->upcomingGames(1610612746, 7);

$hustle = new NBALive\NBABoxScoreHustle("0022301203");

//Or set game id with
$hustle->game_id = "0022301203";

//Creates these arrays
$hustle->home_players;
$hustle->away_team;
$hustle->home_team;
$hustle->away_team;

$sum = new NBALive\NBAGameSummary("0022301203");

//Or set game id with
$sum->game_id = "0022301203";

//Creates these arrays
$sum->home;
$sum->away;
$sum->refs;
$sum->inactive;
$sum->home_line_score;
$sum->away_line_score;
$sum->last_meeting;
$sum->statuses;

//Int
$sum->attendance;

$roster = new NBALive\NBARosters(1610612754, '2014-15');

//Creates the array
$roster->players;
$roster->coaches;

$stat = 'PTS';
$mode = 'Totals'
$season = '2023-24'
$type = 'Regular+Season'

$ll = new NBALive\NBALeagueLeaders($stat, $mode, $season, $type);

//Creates the array
$ll->details;

$yoy = new NBALive\NBAPlayerYearOverYear();
$yoy->player_id = 202331;//Required
$yoy->per_mode = 'PerGame';
//Set this if you want to get a specific season:
$yoy->season = '2019-20';

//Must run fetch()
$yoy->fetch();

//Creates the arrays
$yoy->details;
//For the specific season
$yoy->season_array;

$on_off = new NBALive\NBATeamPlayerOnOff();
$on_off->team_id = 1610612746;
$on_off->season = '2023-24';

//Must run fetch()
$yoy->fetch();

//Creates the arrays
$yoy->on;
$yoy->off;

//Get a specific player on and off
$on_off->player(201587);

//This build and returns:
$on_off->player_only;

$player = new NBALive\NBAPlayerShooting();

//Or set player id with
$player->player_id = 202331;
$player->season = '2019-20';

//Creates the arrays
$player->shot_5ft = [];
$player->shot_8ft = [];
$player->shot_area = [];
$player->assisted = [];
$player->shot_types_summary = [];
$player->shot_types = [];
$player->assisted_by = [];

$player = new NBALive\NBAPlayer(202331);

//Or set player id with
$player->player_id = 202331;

//Creates the arrays
$player->details;
$player->seasons;

$awards = new NBALive\NBAPlayerAwards(202331);

//Creates the array
$player->awards;

$awards = new NBALive\NBAPlayerCareer(202331, 'Totals');

//Creates the arrays
$player->season_totals_regular;
$player->career_totals_regular;
$player->season_totals_post;
$player->career_totals_post;
$player->season_totals_all_star;
$player->career_totals_all_star;
$player->season_totals_college;
$player->career_totals_college;
$player->season_totals_showcase;
$player->career_totals_showcase;
$player->season_rankings_regular;
$player->season_rankings_post;

$series = new NBALive\NBAPlayoffBracket('2023');

$all = $series->results;
$east = $series->east;
$west = $series->west;

$in_progress = $series->in_progress;
$completed = $series->completed;

$playoffs = new NBALive\NBAPlayoffPicture('22023');


$playoff_series = new NBALive\NBAPlayoffSeries('2023-24');

$team = new NBALive\NBATeam(1610612757);


//Or set team id with
$team->team_id = 1610612757;

//Creates the array
$team->details;

$teams = new NBALive\NBATeamYears();

//Creates the array
$teams->teams;

$match_ups = new NBALive\NBAMatchups();
$match_ups->season = '2023-24';

//Get only players from a team with
$match_ups->off_team_id = 1610612757;

//Get only certain player
$match_ups->off_player_id = 202331;

//Call fetch
$match_ups->fetch();

//Creates the array
$match_ups->details;

$shots = new NBALive\NBALeaguePlayerShotLocations();
$shots->season = '2023-24';

//Get only players from a team with
$shots->team_id = 1610612757;

//Choose location/range type
$shots->distance_range = 'By Zone';
$shots->distance_range = '5ft Range';
$shots->distance_range = '8ft Range';

//Creates the arrays depending on distance_range
$shots->zone;
$shots->range_5ft;
$shots->range_8ft;

$shots = new NBALive\NBALeaguePlayerShotPts();
$shots->season = '2023-24';

//Get only players from a team with
$shots->team_id = 1610612757;

//Creates the array
$shots->details;

$ve = new NBALive\NBAVideoEvents(1, '0022300568');

//Creates the array
$ve->details;
json
[
  {
    "game_id": "0022300364",
    "game_sequence": 1,
    "game_status": 1,
    "game_status_text": "7:00 pm ET",
    "game_code": "20231220\/UTACLE",
    "home_tid": 1610612739,
    "away_tid": 1610612762,
    "arena": "Rocket Mortgage FieldHouse",
    "live_period": null,
    "date_time_et": "2023-12-20 19:00:00",
    "date_time_utc": "2023-12-21 00:00:00"
  },
  {
    "game_id": "0022300365",
    "game_sequence": 2,
    "game_status": 1,
    "game_status_text": "7:00 pm ET",
    "game_code": "20231220\/CHAIND",
    "home_tid": 1610612754,
    "away_tid": 1610612766,
    "arena": "Gainbridge Fieldhouse",
    "live_period": null,
    "date_time_et": "2023-12-20 19:00:00",
    "date_time_utc": "2023-12-21 00:00:00"
  },
  {
    "game_id": "0022300366",
    "game_sequence": 3,
    "game_status": 1,
    "game_status_text": "7:00 pm ET",
    "game_code": "20231220\/MIAORL",
    "home_tid": 1610612753,
    "away_tid": 1610612748,
    "arena": "Amway Center",
    "live_period": null,
    "date_time_et": "2023-12-20 19:00:00",
    "date_time_utc": "2023-12-21 00:00:00"
  },
  {
    "game_id": "0022300367",
    "game_sequence": 4,
    "game_status": 1,
    "game_status_text": "7:00 pm ET",
    "game_code": "20231220\/MINPHI",
    "home_tid": 1610612755,
    "away_tid": 1610612750,
    "arena": "Wells Fargo Center",
    "live_period": null,
    "date_time_et": "2023-12-20 19:00:00",
    "date_time_utc": "2023-12-21 00:00:00"
  },
  {
    "game_id": "0022300368",
    "game_sequence": 5,
    "game_status": 1,
    "game_status_text": "7:30 pm ET",
    "game_code": "20231220\/NYKBKN",
    "home_tid": 1610612751,
    "away_tid": 1610612752,
    "arena": "Barclays Center",
    "live_period": null,
    "date_time_et": "2023-12-20 19:30:00",
    "date_time_utc": "2023-12-21 00:30:00"
  },
  {
    "game_id": "0022300369",
    "game_sequence": 6,
    "game_status": 1,
    "game_status_text": "7:30 pm ET",
    "game_code": "20231220\/DENTOR",
    "home_tid": 1610612761,
    "away_tid": 1610612743,
    "arena": "Scotiabank Arena",
    "live_period": null,
    "date_time_et": "2023-12-20 19:30:00",
    "date_time_utc": "2023-12-21 00:30:00"
  },
  {
    "game_id": "0022300370",
    "game_sequence": 7,
    "game_status": 1,
    "game_status_text": "8:00 pm ET",
    "game_code": "20231220\/LALCHI",
    "home_tid": 1610612741,
    "away_tid": 1610612747,
    "arena": "United Center",
    "live_period": null,
    "date_time_et": "2023-12-20 20:00:00",
    "date_time_utc": "2023-12-21 01:00:00"
  },
  {
    "game_id": "0022300371",
    "game_sequence": 8,
    "game_status": 1,
    "game_status_text": "8:00 pm ET",
    "game_code": "20231220\/ATLHOU",
    "home_tid": 1610612745,
    "away_tid": 1610612737,
    "arena": "Toyota Center",
    "live_period": null,
    "date_time_et": "2023-12-20 20:00:00",
    "date_time_utc": "2023-12-21 01:00:00"
  },
  {
    "game_id": "0022300372",
    "game_sequence": 9,
    "game_status": 1,
    "game_status_text": "8:30 pm ET",
    "game_code": "20231220\/LACDAL",
    "home_tid": 1610612742,
    "away_tid": 1610612746,
    "arena": "American Airlines Center",
    "live_period": null,
    "date_time_et": "2023-12-20 20:30:00",
    "date_time_utc": "2023-12-21 01:30:00"
  },
  {
    "game_id": "0022300373",
    "game_sequence": 10,
    "game_status": 1,
    "game_status_text": "10:00 pm ET",
    "game_code": "20231220\/BOSSAC",
    "home_tid": 1610612758,
    "away_tid": 1610612738,
    "arena": "Golden 1 Center",
    "live_period": null,
    "date_time_et": "2023-12-20 22:00:00",
    "date_time_utc": "2023-12-21 03:00:00"
  }
]