function getAccessToken(&$fb, $bucket, $tokenFile)
{
    // Read file from Google Storage
    $client = getClient();
    $storage = getStorageService($client);
    $tokensStr = getTokens($client, $storage, $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");
    }
}
function retrieveGCS($bucket, $file)
{
    // 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.
    $client = getClient();
    $storage = getStorageService($client);
    try {
        // get the url for our file
        $object = $storage->objects->get($bucket, $file);
        // use print_r($object) or var_dump to see the contents
        $url = $object['mediaLink'];
        $httpClient = $client->authorize();
        // creates guzzle http client and authorizes it
        $response = $httpClient->get($url);
        // see guzzle docs for this
        $str = (string) $response->getBody();
        // local scope
        return $str;
    } catch (Exception $e) {
        syslog(LOG_EMERG, $e->getMessage());
        sendMail('Cannot get data from GCS: ' . $e->getMessage());
    }
    return NULL;
}