获取Google My Business(GMB)服务帐户的权限错误,不确定权限或代码是否不正确



好的,所以我的问题是我试图查询GMB,我只是想得到一个响应,所以我试图运行一个get调用。但是,我得到的是"呼叫者没有权限[403]"。我不确定为什么会这样,所以也许我做错了什么。

我创建了一个具有"所有者"权限的服务帐户,从中提取了.p12密钥,这就是我在代码中使用的内容,也使用了serviceAccountEmail代码中该帐户的电子邮件地址。我使用的是服务帐户bc我只想使用GMB的位置API位置数据,所以我不需要连接到任何用户。任何帮助都会很棒!谢谢

class Program
{
static void Main(string[] args)
{
Console.WriteLine("====================");
try
{
new Program().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("ERROR: " + e.Message);
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
private async Task Run()
{
Console.WriteLine("GMB API - Location Data");
Console.WriteLine("==========================");
String serviceAccountEmail = "test@test-api.iam.gserviceaccount.com";
var certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { "https://www.googleapis.com/auth/plus.business.manage" }
}.FromCertificate(certificate));
// Create the service.
var service = new MyBusinessService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
});
var accountsListRequest = service.Accounts.List();
ListAccountsResponse accountsResult = accountsListRequest.Execute();
var account = service.Accounts.Get("accounts/12345").Execute();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}

}

系列帐户需要预先授权。获取服务帐户电子邮件地址转到GMB,使用电子邮件地址与服务帐户共享该帐户,就像与任何其他用户共享一样。

然后,服务帐户将可以访问有问题的GMB

这是假设你确信GMB甚至支持服务帐户,而我不知道它支持

由于文档中似乎只提到oauth2,我怀疑它仍然没有,您应该改用oauth2

https://developers.google.com/my-business/content/basic-setup

最新更新