<?php // Types: add, drop, commish, trade // @todo Do something useful here with transactions although they are archived at Yahoo alrady (no 100 limit) require './inc/config.inc.php'; require './inc/header.php'; try { $m = new YahooFantasyAPI(TRUE); } catch (OauthException $e) { echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL; exit; } // @todo verify lid format (x.x.x) // @todo verify proper type (add, drop, commish, trade, ... others?) $lid = empty($_GET['lid']) ? FALSE : trim($_GET['lid']); $type = empty($_GET['type']) ? 'add' : trim($_GET['type']); if (empty($lid)) { $lids = $m->getLeagueIds(FALSE); if (!$lids) { echo 'Error: Unable to find league ids for you.', PHP_EOL; exit; } echo "<h3>Choose a League ID</h3>"; echo "<ul>"; foreach ($lids as $lid) { echo "<li>"; echo '<a href="transactions.php?lid=' . $lid['league_key'] . '">' . $lid['name'] . ' (' . $lid['season'] . ')</a>'; echo "</li>"; } exit; }
<?php require './inc/config.inc.php'; require './inc/header.php'; // @todo add proper error reporting if (empty($_VARS['week_num']) || empty($_VARS['league_key'])) { echo 'Error: A week number and league key is required for matchup information'; exit; } try { $m = new YahooFantasyAPI(TRUE); } catch (OauthException $e) { echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL; exit; } $query = "league/{$_VARS['league_key']}/scoreboard;week={$_VARS['week_num']}/matchups/teams/roster;week={$_VARS['week_num']}/players/stats;type=week;week={$_VARS['week_num']}"; // For single team // $query = "team/{$team_key}/roster;week={$week_num}/players/stats;type=week;week={$week_num} $minfo = $m->retrieve($query); // @todo fix questionable error handling if (empty($minfo)) { echo "FAIL"; exit; } echo '<h1>Matchup information for week ', $minfo->league->scoreboard->week, '</h1>'; // @todo remove this hack // @todo show more info foreach ($minfo->league->scoreboard->matchups->matchup as $key => $values) { $team_name_0 = $values->teams->team[0]->name; $team_name_1 = $values->teams->team[1]->name; // @todo Assuming one manager for now
<?php require './inc/config.inc.php'; require './inc/header.php'; try { $m = new YahooFantasyAPI(TRUE); } catch (OauthException $e) { echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL; exit; } $ids = $m->getLeagueIds(FALSE); if (!$ids) { echo 'Error: Unable to find league ids for you.', PHP_EOL; exit; } if (isset($_GET['v']) && $_GET['v'] === '1' && isset($_GET['lk'])) { echo 'Hello, I am getting messages. ', PHP_EOL; $count = 0; $data = $m->getMessages(1, 100, $_GET['lk']); foreach ($data->league->messages->message as $message) { echo "<pre>"; print_r($message); echo "</pre>"; } } $linfos = $m->getLeagueInfo($ids); // @todo reduce number of rest calls echo '<dl>'; foreach ($linfos->league as $linfo) { if (!($mcount = $m->getMessageCount($linfo->league_key))) { $mcount = "Count unavailable, no longer available to the Y! API";
<?php /* Authentication flow. Requests and stores an OAuth based token. See the following for details: - http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html */ require './inc/config.inc.php'; try { $o = new OAuth(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI); $o->enableDebug(); $m = new YahooFantasyAPI(FALSE); /******************************************************************************************************************************************** /** Stage #1: Request Token /********************************************************************************************************************************************/ if (empty($_GET['oauth_token']) && empty($_GET['oauth_verifier'])) { $response = $o->getRequestToken('https://api.login.yahoo.com/oauth/v2/get_request_token', APPLICATION_URL . $_SERVER['SCRIPT_NAME']); if ($response && is_array($response)) { if (!$m->saveRequest($response)) { echo "Unable to save response."; $m->printR($m->getLog()); exit; } // @todo add error reporting if (empty($response['xoauth_request_auth_url'])) { $m->printR($m->getLog()); echo 'Error: Did not receive authentication url. Hmm...', PHP_EOL; exit; } header('Location: ' . $response['xoauth_request_auth_url']); exit; } else { // @todo add error reporting
<?php require './inc/config.inc.php'; require './inc/header.php'; try { $m = new YahooFantasyAPI(TRUE); } catch (OauthException $e) { echo "ERROR: Response: " . $e->lastResponse . PHP_EOL; exit; } try { $info = $m->getStoredInfo(); $ids = $m->getLeagueIds(FALSE); // Get league keys foreach ($ids as $id) { // @todo A few are missing this, research this if (FALSE === strpos($id['url'], 'http://')) { $id['url'] = 'http://football.fantasysports.yahoo.com' . $id['url']; } $ldata[] = array('league_key' => $id['league_key'], 'league_id' => $id['league_id'], 'url' => $id['url'], 'season' => $id['season'], 'name' => $id['name']); } echo "<h3>All leagues you have played in</h3>"; echo "<ul>"; foreach ($ldata as $data) { echo "<li><a href='{$data['url']}'>{$data['name']} ({$data['season']})</a></li>"; } echo "</ul>"; } catch (OAuthException $e) { print "<pre>"; echo "Exception caught!\n"; echo "Response: " . $e->lastResponse . "\n";
<?php require './inc/config.inc.php'; require './inc/header.php'; define('PHP_SELF', htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8')); try { $m = new YahooFantasyAPI(TRUE); } catch (OauthException $e) { echo 'ERROR: Response: ', $e->lastResponse, PHP_EOL; exit; } $info = $m->getStoredInfo(); echo '<h3>Stored authentication information</h3>', PHP_EOL; echo '<p>GUID of user: '******'xoauth_yahoo_guid'], '</p>', PHP_EOL; $guid = $info['xoauth_yahoo_guid']; ?> <h1>Run Yahoo arbitrary REST or YQL commands</h1> <p>Note: The "http://fantasysports.yahooapis.com/fantasy/v2/" part is optional and the default for REST commands.</p> <p>Note: We determined your GUID is: <strong><?php echo $guid; ?> </strong> so replace {guid} with it where needed.</p> <p>Note: This OAuth token is specific to Fantasy Sports although a lot of other (but not all) information can be accessed here too. Like your profile.</p> <p>Examples:</p> <ul> <li>REST: view your team(s) info for the current year: users;use_login=1/games;game_keys=nfl,mlb,nba,nhl/teams [<a href="<?php echo PHP_SELF; ?> ?command=users;use_login=1/games;game_keys=nfl,mlb,nba,nhl/teams">run</a>]</li> <li>YQL: view your team(s) info in 2016: SELECT * FROM fantasysports.leagues where use_login=1 and game_key='359' [<a href="<?php