Skip to content

Instantly share code, notes, and snippets.

@luissquall
Last active December 18, 2015 05:29
Show Gist options
  • Save luissquall/5732977 to your computer and use it in GitHub Desktop.
Save luissquall/5732977 to your computer and use it in GitHub Desktop.
<?php
require_once '../src/Google_Client.php';
function pr($content) {
echo '<pre>';
print_r($content);
echo '</pre>';
}
const CLIENT_ID = 'XXXX';
const SERVICE_ACCOUNT_NAME = 'XXXX';
const KEY_FILE = 'privatekey.p12';
$client = new Google_Client();
$client->setApplicationName("App");
session_start();
if (isset($_SESSION['token'])) {
echo $_SESSION['token'];
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array(
'https://www.googleapis.com/auth/admin.directory.user',
'https://www.googleapis.com/auth/admin.directory.group'
),
$key)
);
$client->setClientId(CLIENT_ID);
$req = new Google_HttpRequest("https://www.googleapis.com/admin/directory/v1/groups?domain=googleappsforeducationdomain.com");
$resp = $client::getIo()->authenticatedRequest($req);
print "<h1>Single User</h1>: <pre>" . $resp->getResponseBody() . "</pre>";
if ($client->getAccessToken()) {
pr($client->getAccessToken());
$_SESSION['token'] = $client->getAccessToken();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment