$client = new Google_Client(); $client->setAccessType('offline'); $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); $client->setRedirectUri(REDIRECT_URI); $client->setScopes(SCOPES); // authorization code exchange step $authCode = $_GET['code']; $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); // get the access token $token = $accessToken['access_token'];
$client = new Google_Client(); $client->setAccessType('offline'); $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); $client->setRedirectUri(REDIRECT_URI); $client->setScopes(SCOPES); // authorization code exchange step $authCode = $_GET['code']; $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); // get the access token $token = $accessToken['access_token'];In both examples, the `getAccessToken` method is not explicitly called, but is used internally by the `fetchAccessTokenWithAuthCode` method to retrieve and return the access token. The package library for this method is the Google API PHP client library, which can be installed using Composer or downloaded from the Google Developers website.