如何使用服务帐户发出 Google Home Graph 请求?

问题描述

我想创建一个可以控制 Google Home Devices 的桌面应用程序。在过去的几个小时里,我一直在为 Google Homegraph 身份验证过程苦苦挣扎。

我创建了一个服务帐户并将 JSON 文件添加到项目文件中。我正在以这种方式创建凭据:

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"
                });
            }

要创建任何请求,我需要提供一个 AgentUserIdServiceCredservice 本身 (ApiKey) 中的任何 ID 都会导致代码为 400 错误的异常。 credentialsGoogleCredential 类型)没有我可以提供的任何类型的 ID。

如何使用服务帐户请求从 Google Home Graph 获取设备?

另一件事是,当我尝试将 HomeGraphServiceService.Scope.Homegraph 范围添加到 Google 项目 - API Playground 中的任何位置时,此应用程序 - 它会导致代码 400 错误 - OAuth 页面上的无效范围。

Error 400 on Google OAuth Page

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)