google photos api save token?

  google-api, google-oauth, google-photos, php

i am using this library
i am using samples included there the problem i am having is that the code there relies on _SESSION to store the token i am trying to use it, in the background meaning i do it once sve it on a file and refresh it if needed .
i couldn’t find how to do it most of the documentation i found was for google client api not this one
any help is appreciated
how do i do this ?

i have tried adding a token_access.json where i try to insert access token after auth redirect

function connectWithGooglePhotos(array $scopes, $redirectURI)
    $clientSecretJson = json_decode(
    $clientId = $clientSecretJson['client_id'];
    $clientSecret = $clientSecretJson['client_secret'];

    $oauth2 = new OAuth2([
        'clientId' => $clientId,
        'clientSecret' => $clientSecret,
        'authorizationUri' => '',
        // Where to return the user to if they accept your request to access their account.
        // You must authorize this URI in the Google API Console.
        'redirectUri' => $redirectURI,
        'tokenCredentialUri' => '',
        'scope' => $scopes,

    // The authorization URI will, upon redirecting, return a parameter called code.
    if (!isset($_GET['code'])) {
        $authenticationUrl = $oauth2->buildFullAuthorizationUri(['access_type' => 'offline']);
        header("Location: " . $authenticationUrl);
    } else {
        // With the code returned by the OAuth flow, we can retrieve the refresh token.
        $authToken = $oauth2->fetchAuthToken();
        $refreshToken = $authToken['access_token'];

        // The UserRefreshCredentials will use the refresh token to 'refresh' the credentials when
        // they expire.
        $_SESSION['credentials'] = new UserRefreshCredentials(
                'client_id' => $clientId,
                'client_secret' => $clientSecret,
                'refresh_token' => $refreshToken
            $tokenStoragePath ='../../access_token.json';

        file_put_contents($tokenStoragePath, $refreshToken);

        // Return the user to the home page.
        header("Location: index.php");

after about an hour the token expires how do i refresh it ?
since mose doculmentation talks about google api , not this one

Source: Ask PHP