我一直在尝试访问Googles Mybusiness API,但它似乎比文档说明要困难一些 .

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

'Error:"invalid_request", Description:"Invalid impersonation prn email address.", Uri:""'

据我所知,这表明该服务帐户无权模拟在Google我的商家中设置为管理员的帐户 .

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

如何授予服务帐户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,
        });