I have a Google Drive under my personal Google account. I have also set up a Google App with service account under my personal Google account. That service account has Owner role.
I am trying to use the service account to get listing of recent activity on some folder in my Google Drive. I added the service account email as a shared user for the folder with Edit permission. But whenever I run the Google Activity API I get no results for activities, even though I am doing various things in the shared folder, like adding files.
I am doing this in PHP via
$client = new Google_Client();
$client->setApplicationName('Some App');
$client->setAuthConfig( __DIR__ . '/service_account.json');
$client->setScopes(Google_Service_DriveActivity::DRIVE_ACTIVITY_READONLY);
$client->fetchAccessTokenWithAssertion();
$service = new Google_Service_DriveActivity($client);
// Print the recent activity in your Google Drive.
$request = new Google_Service_DriveActivity_QueryDriveActivityRequest();
$request->setPageSize(10);
$results = $service->activity->query($request);
if (count($results->getActivities()) == 0) {
print "No activity.\n";
else // do something
It always triggers "No activity". I step through the code, and there are no errors. The project the service account is attached to has Google Activity API enabled.
Maybe this doesn't work because the service account is not the one doing the activities? Though I thought the whole point of a service account is to get data access on behalf of someone (in this case the someone being myself).
I just did test - I used my Oauth2 credentials for my app instead of the service account credentials and it works. But that is the thing - I really need this working for service account.