I would like to do caching for folder content, therefore it will be cool if I can somehow get an information if folder in google drive changed and then flush the cache. Is there a way for that? Best in php.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
After some time I came up with this nice solution:
function isGoogleDriveFolderContentUpdated($lastTime, $folderId, &$client)
{
$appsactivityService = new Google_Service_Appsactivity($client);
$optParams = array(
'source' => 'drive.google.com',
'drive.ancestorId' => $folderId,
'pageSize' => 1,
);
$results = $appsactivityService->activities->listActivities($optParams);
if (count($results->getActivities()) == 0) {
return 0;
} else {
$activities = $results->getActivities();
$activity = $activities[0];
$event = $activity->getCombinedEvent();
$activityTime = date(DateTime::RFC3339, $event->getEventTimeMillis() / 1000);
$lastTime = strtotime($lastTime);
$activityTime = strtotime($activityTime);
if ($activityTime > $lastTime) {
//folder content changed since last check
return 1;
}
return 0;
}
}
which can be used like:
echo isGoogleDriveFolderContentUpdated("2018-11-26T21:03:57+01:00" ,"1A9CXgB44F1khfDAzU4t0R322TWh", $client);
where a first argument is a datetime of last check, second google drive folder id, and the last reference for client variable.
Also your app should have a scope for: https://www.googleapis.com/auth/activity
otherwise you will get an error.