Skip to content

Instantly share code, notes, and snippets.

@luissquall
Created June 10, 2013 22:02
Show Gist options
  • Save luissquall/5752799 to your computer and use it in GitHub Desktop.
Save luissquall/5752799 to your computer and use it in GitHub Desktop.
<?php
require_once "../../google-api-php-client/src/Google_Client.php";
require_once "../../google-api-php-client/src/contrib/Google_DriveService.php";
require_once "../../google-api-php-client/src/contrib/Google_Oauth2Service.php";
require_once "../basics.php";
require_once "../config.php";
function buildClient($scopes, $sub = false) {
$key = file_get_contents(SERVICE_ACCOUNT_PKCS12_FILE_PATH);
$auth = new Google_AssertionCredentials(
SERVICE_ACCOUNT_EMAIL,
$scopes,
$key
);
$auth->sub = $sub;
$client = new Google_Client();
$client->setUseObjects(true);
$client->setAssertionCredentials($auth);
return $client;
}
session_start();
$scopes = array(
"https://www.googleapis.com/auth/admin.directory.group",
"https://www.googleapis.com/auth/admin.directory.user"
);
$client = buildClient($scopes);
// Option 1. Send raw HTTP request
$req = new Google_HttpRequest("https://www.googleapis.com/admin/directory/v1/groups?domain=domain.edu");
$resp = $client::getIo()->authenticatedRequest($req);
$respBody = $resp->getResponseBody();
pr($respBody);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment