Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to refresh an expired token? #576

Open
mahdi-above opened this issue Sep 4, 2024 · 0 comments
Open

How to refresh an expired token? #576

mahdi-above opened this issue Sep 4, 2024 · 0 comments

Comments

@mahdi-above
Copy link

I used the steps from this page to get the access token. Now I have the access token and refresh token.

How can you refresh the access_token using the refresh token?

googleapis/php-analytics-data@175f05d#top

$oauth = new OAuth2([
    'scope' => 'https://www.googleapis.com/auth/analytics.readonly',
    'tokenCredentialUri' => 'https://oauth2.googleapis.com/token',
    'authorizationUri' => $keys->{'web'}->{'auth_uri'},
    'clientId' => $keys->{'web'}->{'client_id'},
    'clientSecret' => $keys->{'web'}->{'client_secret'},
    'redirectUri' => 'http://' . $_SERVER['HTTP_HOST'] . '/',
]);
    $auth_url = $oauth->buildFullAuthorizationUri();
    header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
    // If an OAuth2 authorization code is present in the URL, exchange it for
    // an access token.
    $oauth->setCode($_GET['code']);
    $oauth->fetchAuthToken();

    // Persist the acquired access token in a session.
    $_SESSION['access_token'] = $oauth->getAccessToken();

    // Refresh the current page.
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));

Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant