问题描述
我无法获取在 Google Home Graph API 中执行任何请求所需的代理用户 ID。 API 为 operated by a Service Account
,但是,Google Home Graph [https://www.googleapis.com/auth/homegraph] 的范围无效。
此范围无法在任何地方进行身份验证,尤其是在 Google 的 OAuth Playground 中,您应该从中获取请求的代理用户 ID。
如果 Home Graph Scope 无效且无法通过身份验证,如何获取 Agent User Id 并执行 Home Graph 请求?
或者,如何验证当前显示无效的错误的 Google Home Graph Scope?
通过这种方式从服务帐户的 JSON 文件中检索凭据:
string[] Scopes = { HomeGraphServiceService.ScopeConstants.Homegraph };
ServiceAccountCredential ServiceCred
using (FileStream stream = new FileStream("MainCredentials.json",FileMode.Open,FileAccess.ReadWrite))
{
ServiceCred = ServiceAccountCredential.FromServiceAccountData(stream);
GoogleCredential credentials = GoogleCredential.FromServiceAccountCredential(ServiceCred).CreateScoped(Scopes);
var service = new HomeGraphServiceService(new BaseClientService.Initializer()
{
HttpClientinitializer = credentials,ApplicationName = "Test Application",});
}
我现在唯一能做的就是将服务帐户凭据 JSON 文件加载到 GoogleCredential
或 ServiceAccountCredential
,但没有 AgentUserId
我什么也做不了。>
解决方法
您需要create a Smart Home Action in the Actions Console,在此处提供您的履行网址。
您还需要在控制台中提供您的授权和令牌 URL,它们需要与您使用的端点匹配 retrieve your AgentUserID through the OAuth Playground tool。