Ted*_*erg 5 google-api google-api-dotnet-client google-my-business-api
我正在尝试使用服务帐户通过 Google 我的商家 API 检索位置/评论。
到目前为止我有:
当使用 Google 的示例 .NET 客户端(可从https://developers.google.com/my-business/sampleshttps://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;
}
Run Code Online (Sandbox Code Playgroud)
接下来我创建一个初始化程序,例如:
var initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My GMB API Client",
GZipEnabled = true,
};
Run Code Online (Sandbox Code Playgroud)
最后我创建一个MyBusinessService实例,例如:var service = new MyBusinessService(initializer);
我可以列出邀请:
service.Accounts
.Invitations
.List("[ACCOUNT NAME]")
.Execute()
.Invitations;
Run Code Online (Sandbox Code Playgroud)
但是,尝试接受邀请失败:
service.Accounts
.Invitations
.Accept(null, "[INVITATION NAME]")
.Execute();
Run Code Online (Sandbox Code Playgroud)
第一个参数null正如本文档所述,请求正文应该为空。
或者是否有其他方式接受邀请,以便服务帐户能够检索我们所在位置的“Google 我的商家”评论?
小智 1
GMB API 中的服务帐户无法替代 Google 用户帐户身份验证。您需要将 Oauth 与用户帐户 \xe2\x80\x94(例如,有权访问 GMB Web 界面的 Gmail 帐户)一起使用 - 以便您可以代表用户执行操作。
\n| 归档时间: |
|
| 查看次数: |
1518 次 |
| 最近记录: |