1. Go to this page and download the library: Download jaeger/google-apiclient library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jaeger / google-apiclient example snippets
// include your composer dependencies
nt->setApplicationName("Client_Library_Examples");
$client->setDeveloperKey("YOUR_APP_KEY");
$service = new Google_Service_Books($client);
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
$client = new Google_Client();
$client->setAuthConfig('/path/to/client_credentials.json');
$client->addScope(Google_Service_Drive::DRIVE);
// Your redirect URI can be any registered URI, but in this example
// we redirect back to this same page
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client->setRedirectUri($redirect_uri);
if (isset($_GET['code'])) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token);
}
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Drive::DRIVE);
$client->setSubject($user_to_impersonate);
// create the datastore service class
$datastore = new Google_Service_Datastore($client)
// build the query - this maps directly to the JSON
$query = new Google_Service_Datastore_Query([
'kind' => [
[
'name' => 'Book',
],
],
'order' => [
'property' => [
'name' => 'title',
],
'direction' => 'descending',
],
'limit' => 10,
]);
// build the request and response
$request = new Google_Service_Datastore_RunQueryRequest(['query' => $query]);
$response = $datastore->projects->runQuery('YOUR_DATASET_ID', $request);
// create the datastore service class
$datastore = new Google_Service_Datastore($client)
// build the query
$request = new Google_Service_Datastore_RunQueryRequest();
$query = new Google_Service_Datastore_Query();
// - set the order
$order = new Google_Service_Datastore_PropertyOrder();
$order->setDirection('descending');
$property = new Google_Service_Datastore_PropertyReference();
$property->setName('title');
$order->setProperty($property);
$query->setOrder([$order]);
// - set the kinds
$kind = new Google_Service_Datastore_KindExpression();
$kind->setName('Book');
$query->setKinds([$kind]);
// - set the limit
$query->setLimit(10);
// add the query to the request and make the request
$request->setQuery($query);
$response = $datastore->projects->runQuery('YOUR_DATASET_ID', $request);
// create the Google client
$client = new Google_Client();
/**
* Set your method for authentication. Depending on the API, This could be
* directly with an access token, API key, or (recommended) using
* Application Default Credentials.
*/
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Plus::PLUS_ME);
// returns a Guzzle HTTP Client
$httpClient = $client->authorize();
// make an HTTP request
$response = $httpClient->get('https://www.googleapis.com/plus/v1/people/me');
$cache = new Stash\Pool(new Stash\Driver\FileSystem);
$client->setCache($cache);
$logger = new Monolog\Logger;
$tokenCallback = function ($cacheKey, $accessToken) use ($logger) {
$logger->debug(sprintf('new access token received at cache key %s', $cacheKey));
};
$client->setTokenCallback($tokenCallback);
// FOR DEBUGGING ONLY
$httpClient = new GuzzleHttp\Client([
'proxy' => 'localhost:8888', // by default, Charles runs on localhost port 8888
'verify' => false, // otherwise HTTPS requests will fail.
]);
$client = new Google_Client();
$client->setHttpClient($httpClient);
$opt_params = array(
'alt' => "json"
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.