【发布时间】:2019-10-14 12:09:05
【问题描述】:
我正在尝试使用服务帐户通过 Google My Business API 检索位置/评论。
到目前为止,我有:
- 在 Developers Console 中创建了一个项目
- 启用对 Google My Business API 的访问(已获 Google 批准/列入白名单)
- 创建了一个具有关联 OAuth 身份的服务帐户
- 邀请 OAuth 身份(即服务帐户)作为“Google 我的商家”位置的经理
使用可从https://developers.google.com/my-business/samples 下载的 Google 示例 .NET 客户端以编程方式列出来自 https://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations 的邀请时,我能够看到邀请
但是,当我尝试通过 https://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations/[INVITATION NAME]:accept 接受邀请时,请求失败并出现 500 服务器错误。
在创建MyBusinessService 实例时,我首先创建一个服务帐户凭据,例如:
ServiceAccountCredential credential;
using (Stream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = (ServiceAccountCredential)GoogleCredential
.FromStream(stream)
.CreateScoped(new [] { "https://www.googleapis.com/auth/plus.business.manage" })
.UnderlyingCredential;
}
接下来我创建一个初始化器,如:
var initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My GMB API Client",
GZipEnabled = true,
};
最后我创建了一个MyBusinessService 实例,例如:var service = new MyBusinessService(initializer);
我可以列出邀请:
service.Accounts
.Invitations
.List("[ACCOUNT NAME]")
.Execute()
.Invitations;
但是,尝试接受邀请失败:
service.Accounts
.Invitations
.Accept(null, "[INVITATION NAME]")
.Execute();
第一个参数是null,因为this documentation 表示请求正文应该为空。
或者是否有其他方式可以接受邀请,以使服务帐户能够检索我们所在位置的“Google 我的商家”评论?
【问题讨论】:
-
这方面没有进展吗? Google 正式允许通过服务帐户使用 OAuth 进行服务器到服务器通信:developers.google.com/identity/protocols/oauth2/service-account 我们需要以编程方式获取我们在 Google 上的业务的评论评级。一切正常,但我们无法接受服务帐户的邀请。
标签: google-api google-api-dotnet-client google-my-business-api