nest-device-access

List devices and structures empty


Using the Golang SDK for Smart Device Management, I want to access my Nest thermostat.

I am able to authenticate and successful API calls are being made to the SDM API. However when I call Devices.List(...).Do() the response contains an empty list.

devices, err := sdmService.Enterprises.Devices.List(parent).Do()
if err != nil {
    log.Fatal(err)
}
log.Print("Got devices")
log.Printf("%+v", devices)

The thermostat is definitely associated with the Google account which I am authenticating with.

Is there something I have potentially missed. A simple code reference would be superb!

EDIT

Looks like I might need to add the following scopes in the screenshot below. Which then requires verification. I'd then need to have an appliction homepage, privacy policy, YouTube video showing how I'd use the data.......

How is the suitable for hobbyists?

Google OAuth scopes

EDIT 2

Personal projects are apparently exempt from the verification process. How do I make the project personal! Why is this so hard? (I am RTFM very much!)

Edit 3

Getting it a bit more now. Stopping for the evening. I realise that the statement about personal projects just means, "get on with it, but your users will see a warning screen".

However when I follow the authentication flow no devices appear on the permissions list. I think that this is the problem.


Solution

  • So the problem was on one of the first pages of documentation! Typical. I took a break. Circled back from the top and with a clearer head the document made sense with the additional context I had pieced together.

    I had to change

    conf := &oauth2.Config{
            ClientID:     "...",
            ClientSecret: "...",
            RedirectURL:  "...",
            Scopes: []string{
                smartdevicemanagement.SdmServiceScope,
            },
            Endpoint: google.Endpoint
        }
    

    to

    conf := &oauth2.Config{
            ClientID:     "...",
            ClientSecret: "...",
            RedirectURL:  "...",
            Scopes: []string{
                smartdevicemanagement.SdmServiceScope,
            },
            Endpoint: oauth2.Endpoint{
                AuthURL:  fmt.Sprintf("https://nestservices.google.com/partnerconnections/%s/auth", projectID),
                TokenURL: google.Endpoint.TokenURL,
            },
        }