I'm trying to sync files between Amazon S3 and Google Drive with a service.
I created a service account and shared a folder with its email. Then with the automated service I built, I created some folders.
Everything was fine until I tried to delete these folders from Google Drive UI. They disappeared from the UI, but my service still receives them as if they were present. Here is the code I'm using to list the files/folders:
private function retrieveAllGoogleDriveFiles($service) {
$result = array();
$pageToken = NULL;
do {
try {
$parameters = array();
if ($pageToken) {
$parameters['pageToken'] = $pageToken;
}
$parameters['q'] = "trashed=false";
$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;
}
Here is the authorization mechanism I'm using:
$credentials = new Google_Auth_AssertionCredentials(
'1234567890-somehashvalueshere123123@developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/drive'),
$private_key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer'
);
$googleClient = new Google_Client();
$googleClient->setAssertionCredentials($credentials);
if ($googleClient->getAuth()->isAccessTokenExpired()) {
$googleClient->getAuth()->refreshTokenWithAssertion();
}
$googleService = new Google_Service_Drive($googleClient);
$files_list = $this->retrieveAllGoogleDriveFiles($googleService);
The case where a user deletes a file/folder from Google Drive is real to me and I should make the sync back to S3 and remove the file/folder from there also.
Thanks in advance.