This is my first time using Google App Engine, so some of my terminology might be a bit off, bear with me.
I had some php code running in a web app outside of GAE that was using the google-api-php-client library to access gdrive folders and create files. It was working wonderfully.
I'm trying to migrate to GAE with a project that has domain-wide delegation so that my app can access/create files in my gdrive account. For example, let's say my domain is kennywyland.com and my Google account that I'm using is kenny@kennywyland.com.
I create my Google Client like this, which I got from https://developers.google.com/api-client-library/php/auth/service-accounts:
$client = new Google_Client();
$client->setAuth(new Google_Auth_AppIdentity($client));
$client->getAuth()->authenticateForScope('https://www.googleapis.com/auth/drive');
Then I create the gdrive service like this:
$service = new Google_Service_Drive($client);
I didn't get any errors from this and I am able to perform queries without error messages being thrown, however, I'm getting back completely empty result sets. I've got plenty of files in my gdrive account, so I would assume that I should see them when I publish the following code to GAE and run it (the retreiveAllFiles() function is from Google's code example found here: https://developers.google.com/drive/v2/reference/files/list#try-it):
$allfiles = retrieveAllFiles($service);
print_r($allfiles);
function retrieveAllFiles($service) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$files = $service->files->listFiles($parameters);
$result = array_merge($result, $files->getItems());
$pageToken = $files->getNextPageToken();
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
$pageToken = NULL;
}
} while ($pageToken);
return $result;
}
However, I get an empty result set. The print_r() prints an empty array:
Array ( )
What am I missing? I feel like my project/app is able to successfully access the gdrive server, but it's just not able to see any files in my account associated with this work domain.