You need to enable JavaScript to run this app. 如何使用服务账号发起Google Home Graph请求获取设备列表
优惠活动
大模型
产品
解决方案
定价
更多

如何使用服务账号发起Google Home Graph请求获取设备列表

Google Home Graph 服务账号接入相关问题

开发背景

正在开发用于控制Google Home设备的桌面应用程序,已在认证环节卡系数小时,无法顺利完成Google Home Graph的认证流程。

已完成的前置配置

已在对应Google云项目中创建服务账号(Service Account),并将服务账号对应的JSON凭证文件存入项目工作目录,当前通过如下C#代码逻辑生成接入凭证:

string[] Scopes = { HomeGraphServiceService.Scope.Homegraph }; 
using (FileStream stream = new FileStream("ServiceCredentials.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"
    });
}

当前遇到的异常问题

  • 接口调用400错误问题
    调用任意Home Graph相关接口时,都要求传入AgentUserId参数,不管是尝试使用服务账号凭证文件内的任意ID、还是使用服务实例自带的ApiKey填充该参数,都会触发返回400错误的异常;生成的GoogleCredential类型credentials对象中,没有可匹配该参数要求的标识。
    核心疑问:如何通过已配置的服务账号发起合法请求,从Google Home Graph中获取关联的设备列表。
  • OAuth授权无效作用域问题
    尝试在Google项目配套的API Playground中,为当前应用添加HomeGraphServiceService.Scope.Homegraph作用域时,跳转的OAuth页面会直接返回400错误,提示“Invalid Scope”。

Google OAuth页面400错误

内容的提问来源于stack exchange,提问作者Techrex Studios

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.03 02:36:04