Last active
December 18, 2015 05:29
-
-
Save luissquall/5732977 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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