Google api 访问google api(针对我的业务)时尝试模拟帐户时出错

Google api 访问google api(针对我的业务)时尝试模拟帐户时出错,google-api,google-api-dotnet-client,google-my-business-api,Google Api,Google Api Dotnet Client,Google My Business Api,我一直在尝试访问Google Mybusiness API,但它似乎比文档中的状态要难一些 我已经创建了一个服务帐户,可以访问我所能想到的所有内容,但在尝试连接或访问API资源时,我仍然会收到一个错误消息: 'Error:"invalid_request", Description:"Invalid impersonation prn email address.", Uri:""' 据我所知,这表明服务帐户没有权限模拟在Google My Business中设置为管理员的帐户 我找到的几乎每

我一直在尝试访问Google Mybusiness API,但它似乎比文档中的状态要难一些

我已经创建了一个服务帐户,可以访问我所能想到的所有内容,但在尝试连接或访问API资源时,我仍然会收到一个错误消息:

'Error:"invalid_request", Description:"Invalid impersonation prn email address.", Uri:""'
据我所知,这表明服务帐户没有权限模拟在Google My Business中设置为管理员的帐户

我找到的几乎每个搜索结果都提到服务帐户应该是G套件管理员。服务帐户或GMB管理员都不在任何与G套件相关的设置中,因此即使将该权限添加到服务帐户也没有效果

如何授予服务帐户对API的访问权限

我尝试了几种连接方法。使用证书是我唯一能够添加用户名的证书,该用户名是我希望模拟的用户的用户名:

        var certificate = new X509Certificate2(System.IO.Path.Combine(path, p12FileName), "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

        var initializer = new ServiceAccountCredential.Initializer(serviceAccount)
        {
            Scopes = new[] { "https://www.googleapis.com/auth/plus.business.manage" },
            User = user,
        };

        var credential = new ServiceAccountCredential(initializer.FromCertificate(certificate))
        {
        };

        var myBusinessService = new MyBusinessService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
        });

请显示用于加载服务帐户凭据和调用API的代码?谢谢。@Chris,我在OP中添加了一些代码:)谢谢。我真的不知道有关GMB的任何具体信息,但您可以从JSON加载服务凭据,并设置用户和作用域:
GoogleCredential.FromFile(…).CreateWithUser(…).CreateScoped(…)
。您还可能会发现此线程非常有用:谢谢@Chris-这里的挑战是google提供的客户端,正在使用google.api libs的v1.10。该版本中不存在FromFile和CreateWithUser方法。