From 5c7f2f17f9c471d306955df457c7cab4e5c6ed3b Mon Sep 17 00:00:00 2001 From: Snap Date: Thu, 16 Apr 2015 14:51:26 -0700 Subject: Google's OpenID Connect method $google_client_id & $google_client_secret must be added to db.inc.php! --- .../examples/service-account.php | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 includes/google-api-php-client-master/examples/service-account.php (limited to 'includes/google-api-php-client-master/examples/service-account.php') diff --git a/includes/google-api-php-client-master/examples/service-account.php b/includes/google-api-php-client-master/examples/service-account.php new file mode 100644 index 0000000..46005f5 --- /dev/null +++ b/includes/google-api-php-client-master/examples/service-account.php @@ -0,0 +1,89 @@ +'; //Client ID +$service_account_name = ''; //Email Address +$key_file_location = ''; //key.p12 + +echo pageHeader("Service Account Access"); +if (strpos($client_id, "googleusercontent") == false + || !strlen($service_account_name) + || !strlen($key_file_location)) { + echo missingServiceAccountDetailsWarning(); + exit; +} + +$client = new Google_Client(); +$client->setApplicationName("Client_Library_Examples"); +$service = new Google_Service_Books($client); + +/************************************************ + If we have an access token, we can carry on. + Otherwise, we'll get one with the help of an + assertion credential. In other examples the list + of scopes was managed by the Client, but here + we have to list them manually. We also supply + the service account + ************************************************/ +if (isset($_SESSION['service_token'])) { + $client->setAccessToken($_SESSION['service_token']); +} +$key = file_get_contents($key_file_location); +$cred = new Google_Auth_AssertionCredentials( + $service_account_name, + array('https://www.googleapis.com/auth/books'), + $key +); +$client->setAssertionCredentials($cred); +if ($client->getAuth()->isAccessTokenExpired()) { + $client->getAuth()->refreshTokenWithAssertion($cred); +} +$_SESSION['service_token'] = $client->getAccessToken(); + +/************************************************ + We're just going to make the same call as in the + simple query as an example. + ************************************************/ +$optParams = array('filter' => 'free-ebooks'); +$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams); +echo "

Results Of Call:

"; +foreach ($results as $item) { + echo $item['volumeInfo']['title'], "
\n"; +} + +echo pageFooter(__FILE__); -- cgit v1.2.3