I have a small host which counts 100MB. I need your lib to log in. This lib has 26MB. Its few times bigger than other libs including whole framework. It is not possible to decrease the size or divide it to more than one package? I dont need tests nor games libs .....
If you are using this client for authentication only, you may be able to accomplish your goals using the google/auth library.
If you're not using any APIs in google/apiclient-services, you can prevent it from being installed by adding the following to your root composer.json file:
{
"replace": {
"google/apiclient-services": "self.version"
}
}
If you're using the downloadable package, or need some but not all of the included clients, you could simply delete the unnecessary files and directories from vendor/google/apiclient-services/src.
To use the google/auth package to retrieve an access token for a user, you can do the following:
// Create the auth client
$credenitalsFile = '/path/to/client-credentials.json';
$credentials = json_decode(file_get_contents($credentialsFile), true);
$oauth2 = new Google\Auth\OAuth2([
'client_id' => $credentialsFile['client_id'],
'client_secret' => $credentialsFile['client_secret'],
'scope' => 'https://www.googleapis.com/auth/drive',
]);
// Rudimentary filecache
$accessTokenFile = '/path/to/access-token.json';
if (isset($_GET['code'])) {
$oauth2->setCode($_GET['code']);
// If we have a code back from the OAuth 2.0 flow, exchange that for an access token.
file_put_contents($accessTokenFile, json_encode($oauth2->fetchAuthToken()));
}
if (file_exists($accessTokenFile)) {
// $accessToken has a refresh token because "access_type" is set to "offline"
$accessToken = json_decode(file_get_contents($accessTokenFile), true);
$oauth2->updateToken($accessToken);
} else {
// Redirect the user back to this page after authorization
$redirectUri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$authUri = $oauth2->buildFullAuthorizationUri(['redirect_uri' => $redirectUri]);
// Redirect the user to the authorization URI
header('Location: ' . $authUri);
return;
}
// Make the call with the access token
$middleware = new Google\Auth\Middleware\AuthTokenMiddleware($oauth2);
$stack = GuzzleHttp\HandlerStack::create();
$stack->push($middleware);
$client = new GuzzleHttp\Client([
'handler' => $stack,
'auth' => 'google_auth'
]);
$response = $client->get('https://www.googleapis.com/drive/v3/files');
You can now specify only the services you want in your composer.json! See https://github.com/googleapis/google-api-php-client#cleaning-up-unused-services
This will be released in v2.7 later today
Most helpful comment
You can now specify only the services you want in your
composer.json! See https://github.com/googleapis/google-api-php-client#cleaning-up-unused-servicesThis will be released in
v2.7later today