谷歌活动api服务帐户403

本文关键字:服务 活动 api 谷歌 | 更新日期: 2023-09-27 18:22:23

我正在使用一个服务帐户访问我们域用户的Google Drive,这很有魅力!然而,我现在正试图使用相同的服务帐户来获取谷歌硬盘中的用户活动。

我已授予服务帐户API访问https://www.googleapis.com/auth/activity和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

谷歌活动api服务帐户403

找到了答案。。。只是服务中的一个愚蠢的拼写错误

更改

AppsactivityService.Scope.Drive 
to 
AppsactivityService.Scope.Activity 

thx!