$redirectUri = 'http://xxxxxxx/dashboard/accounts/oauth2callback';$code = $_GET['code'];
$oauth2 = new OAuth2([ 'authorizationUri' => 'https://accounts.google.com/o/oauth2/v2/auth', 'tokenCredentialUri' => 'https://www.googleapis.com/oauth2/v4/token', 'redirectUri' => $redirectUri, 'clientId' => $this->client_id, 'clientSecret' => $this->client_secret, 'scope' => '****']);
$oauth2->setCode($code);$authToken = $oauth2->fetchAuthToken();
// Store the refresh token for your user in your local storage if you// requested offline access.$refreshToken = $authToken['refresh_token'];$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();
Enter code here...$oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId(your oauth2 client id here)
->withClientSecret(your oauth2 client secret here)
->withRefreshToken(your stored refresh token here)
->build();