$CLIENT_ID = 'your_client_id'; $CLIENT_SECRET = 'your_client_secret'; $client = new Google_Client(); $client->setApplicationName("My Project"); $client->setClientId($CLIENT_ID); $client->setClientSecret($CLIENT_SECRET); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $client->setRedirectUri('http://localhost/googleauth.php'); $auth_url = $client->createAuthUrl(); header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
$client = new Google_Client(); $auth = $client->getAuth(); $authUrl = $auth->createAuthUrl();This example shows how to obtain an instance of the Google_Auth_Abstract class through the `getAuth()` method. We then use the `createAuthUrl()` method to generate an authorization URL for the user. The package library that this method belongs to is the Google API PHP client library, which provides access to various Google APIs such as Google Drive, Google Sheets, and Google Analytics.