Created
March 3, 2015 17:53
-
-
Save ianbarber/8d3489c41e831271c999 to your computer and use it in GitHub Desktop.
Query Drive with a service account
This file contains 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 "../vendor/autoload.php"; | |
$client = new Google_Client(); | |
$client->setApplicationName("Service Acccount Test"); | |
$client_id = '985145966381-is5nq94smihmoa2k0567jab6u6vj278c.apps.googleusercontent.com'; | |
$service_account_name = '985145966381-is5nq94smihmoa2k0567jab6u6vj278c@developer.gserviceaccount.com'; | |
$key_file_location = 'foostarter-a27f84b2dec4.p12'; | |
$key = file_get_contents($key_file_location); | |
$cred = new Google_Auth_AssertionCredentials( | |
$service_account_name, | |
array(Google_Service_Drive::DRIVE_READONLY), | |
$key | |
); | |
$cred->sub = "[email protected]"; // For the @example.com Apps delegation. | |
// Remember to cache the access token locally if making multiple calls | |
// and don't just use this function for each request! | |
$client->getAuth()->refreshTokenWithAssertion($cred); | |
$service = new Google_Service_Drive($client); | |
$result = $service->files->listFiles(); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment