function retrieveFile($bucket, $file)
{
    syslog(LOG_DEBUG, "retrieveFile: file " . $file);
    $content = retrieveGCS($bucket, $file);
    if ($content) {
        echo $content;
        return true;
    }
    return false;
}
function getAccessToken(&$fb, $bucket, $tokenFile)
{
    // Read file from Google Storage
    $tokensStr = retrieveGCS($bucket, $tokenFile);
    if (empty($tokensStr)) {
        quit("No more FB access tokens in storage -- login to app ASAP to generate a token");
    } else {
        $tokens = json_decode($tokensStr, true);
        // 'true' will turn this into associative array instead of object
        // Validate the token before use. User may have logged off facebook, or deauthorized this app.
        // shuffle the array to get random order of iteration
        shuffle($tokens);
        //var_dump($tokens);
        foreach ($tokens as $token) {
            $response = $fb->get('/me', $token);
            if (!$response->isError()) {
                // access_token is valid token
                return $token;
            }
        }
        quit("None of the tokens are valid");
    }
}
// Use Google Cloud Storage (not Cloud DataStore, which is a DB). GCS is unstructured data.
// Use this to create buckets and manage: https://console.cloud.google.com/storage/browser?project=zouk-event-calendar
// Code below is generally out of date with documentation. See source in vendor/google/... for correct usage
// I created 1 bucket through web interface (can also be created programmatically). Inside this bucket will be many files.
// /**
//  * Google Cloud Storage API request to retrieve the list of buckets in your project.
//  */
// $projectId = 'zouk-event-calendar';
// $buckets = $storage->buckets->listBuckets($projectId);
//
// foreach ($buckets['items'] as $bucket) {
//     printf("%s\n", $bucket->getName());
//     syslog(LOG_INFO, $bucket->getName());
// }
/** Get tokens already stored **/
$tokensStr = retrieveGCS($bucket, $tokenFile);
if (empty($tokensStr)) {
    $tokens = array();
} else {
    $tokens = json_decode($tokensStr, true);
    // 'true' will turn this into associative array instead of object
}
// Limit size of array to 50
if (count($tokens) > 50) {
    array_shift($tokens);
    // remove one element from beginning
}
// add the new token to end of array
array_push($tokens, $longLivedAccessToken);
//var_dump($tokens);
/***