require_once 'google-api-php-client/vendor/autoload.php'; $client = new Google_Client(); $client->setApplicationName("Google_Client Example"); $client->setDeveloperKey("YOUR_DEVELOPER_KEY"); $client->setClientId('YOUR_CLIENT_ID'); $client->setClientSecret('YOUR_CLIENT_SECRET'); $client->setRedirectUri('YOUR_REDIRECT_URI'); $client->addScope('https://www.googleapis.com/auth/userinfo.email'); if(isset($_GET['code'])) { $token = $client->fetchAccessTokenWithAuthCode($_GET['code']); $client->setAccessToken($token['access_token']); } if ($client->isAccessTokenExpired()) { header('Location: '.$client->createAuthUrl()); } echo "Access token is still valid!";In this code example, the Google_Client object is initialized, and the developer key and other credentials are set. The addScope() function is used to specify the permissions that the app needs to access. When a user accesses the page, the code checks if the user has already authenticated. If not, the page will redirect the user to the Google login page using the createAuthUrl() function. If the user has authenticated, the access token is fetched using fetchAccessTokenWithAuthCode() function and checked if it has already expired using the isAccessTokenExpired() function. If the access token is still valid, "Access token is still valid!" will be displayed. Otherwise, the user will be redirected to the Google login page. The package library used in this code is "google-api-php-client".