0

I want to create a Desktop Application which would control Google Home Devices. For the past couple of hours I've been struggling with the Google Homegraph authentication process.

I created a Service Account and added the JSON file to the project's file. I am creating the credentials this way:

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

To create any request, I need to provide a AgentUserId. Any ID from the ServiceCred or the service itself (ApiKey) results in an exception with a code 400 error. The credentials (of type GoogleCredential) don't have any sort of Id that I can provide.

How to make a request with a Service Account to get devices from the Google Home Graph?

Another thing is, when I try to add the HomeGraphServiceService.Scope.Homegraph scope anywhere in the Google Project - API Playground, this Application - it results in a code 400 error - Invalid Scope on the OAuth page.

Error 400 on Google OAuth Page

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
  • A URL has parameters after the question mark. For google api the id is a string that gets added to the URL. See following for an example : https://developers.google.com/youtube/v3/sample_requests – jdweng Feb 20 '21 at 22:40
  • Which URL do you mean? The one in the Scopes? And does it apply to HomeGraph? – Techrex Studios Feb 20 '21 at 23:53
  • The one in the request. The ID should be the same for any google request. – jdweng Feb 21 '21 at 00:53
  • This authentication URL just won't work, even when I select it in the Google's OAuth Playground to get the AgentUserId, every other Authentication URL than the Home Graph's one works fine, so I'm not able to really do anything. – Techrex Studios Feb 21 '21 at 00:57
  • 1. what makes you think that Home graph api supports service accounts, – Linda Lawton - DaImTo Feb 21 '21 at 13:06
  • Here's the [Documentation for Google Home Graph](https://developers.google.com/assistant/smarthome/reference/rpc/google.home.graph.v1) when it's said "the request must be authorized by a service account" for all the requests. – Techrex Studios Feb 21 '21 at 13:17

0 Answers0