0
votes

I am using a service account to access our domain user's Google Drive, this works like a charm! However I am now trying to use the same service account to get users activity in Google drive.

I have granted the Service Account API access to https://www.googleapis.com/auth/activity and https://www.googleapis.com/auth/drive

and enable the API!

However I always get the error 403, forbidden!

static AppsactivityService BuildService(String userEmail)
    {
        X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH,
            "notasecret", X509KeyStorageFlags.Exportable);
        ServiceAccountCredential credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
            {
                Scopes = new[] { AppsactivityService.Scope.Drive },
                User = userEmail
            }.FromCertificate(certificate));

        // Create the service.
        var service = new AppsactivityService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "mytest app",
        });

        return service;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        var service = BuildService("[email protected]");

        ActivitiesResource.ListRequest listRequest = service.Activities.List();
        listRequest.Source = "drive.google.com";
        listRequest.DriveAncestorId = "root";

        listRequest.PageSize = 10;

        IList<Activity> activities = listRequest.Execute().Activities;

        Console.WriteLine("Activities:");
    }

maybe it takes some time to enable the https://www.googleapis.com/auth/activity

1
found the answer... just a stupid typo in the service change AppsactivityService.Scope.Drive to AppsactivityService.Scope.Activity thx!markus
Markus, feel free to add the fix as a solution, in that way we can get the sense this issue was addressed and other people can see how you solved it.peleyal

1 Answers

0
votes

found the answer... just a stupid typo in the service

change

AppsactivityService.Scope.Drive 
to 
AppsactivityService.Scope.Activity 

thx!