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.
if you check the Auth section of the documentation for the Drive activity api. You will notice that it doesn't say that service accounts are supported.
The reason that its not working well actually it is working is this.
The Activity API consists of the DriveActivity resource, which represents changes made to objects within a user's Google Drive, and the query method, which allows you to retrieve information about those changes.
Its looking for changes for that user. not for a folder or directory on drive which you shared with the service account
The service account is a user and if that user has not changed anything then you are going to see "No activity"
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).
It is in a way, but the you are currently you are doing it on behalf of the service account. You have not delegated permissions to another user. To be clear sharing a folder with a service account does NOT constitute setting up delegation so that it can act on your behalf. So ...
To do that you would need to enabled domain wide delegation from a workspace account. This is something that may be worth trying.