// If there is saved token data to use, set it now
if (!empty($savedToken) && isset($savedToken['access_token'])) {
    $tv->setTokenData(array('access_token' => $savedToken['access_token'], 'refresh_token' => $savedToken['refresh_token'], 'expires_at' => $savedToken['expires_at']));
} else {
    // No token data.
    // So you need to get the user credentials for authentication.
    $tv->setUserCredentials(USERNAME, PASSWORD);
}
// extra parameters to pass in for the "new_token" event callback
$extraParams = array('extra_params' => 'this can be whatever you want');
// attach a listener function for when a new token is generated so you can save it to a database
$tv->on('new_token', function ($tokenData, $extraParams) {
    $accessToken = $tokenData['access_token'];
    $refreshToken = $tokenData['refresh_token'];
    // timestamp when the access token expires
    $expiresAt = $tokenData['expires_at'];
    //============
    // code to save token data to your database
    //============
}, $extraParams);
/*
//********************* 
// Setup the logger for debugging (optional)
//*********************
$authLog = new Log($tv->getAuthentication());
$log = new Log($tv);
*/
/**
 * Get a list of your apps
 */
$apps = $tv->getApps();