google activity api 服务帐号 403

google activity api service account 403

我正在使用服务帐户访问我们域用户的 Google 驱动器,这太棒了!但是,我现在正尝试使用相同的服务帐户在 Google 驱动器中获取用户 activity。

我已授予服务帐户 API 访问 https://www.googleapis.com/auth/activity and https://www.googleapis.com/auth/drive

并启用 API!

但是我总是收到错误 403,禁止!

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("someuser@domain.com");

        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:");
    }

可能需要一些时间才能启用 https://www.googleapis.com/auth/activity

找到答案...只是服务中的一个愚蠢的错字

改变

AppsactivityService.Scope.Drive 
to 
AppsactivityService.Scope.Activity 

谢谢!