1

When I test to report smart home devices state to google, I get the following error:

"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"status": "PERMISSION_DENIED"}

I follow this guide https://developers.google.com/assistant/smarthome/develop/report-state#service-account-key to get Service Account Key。

HttpEntity entity = httpRequest("https://www.googleapis.com/auth/homegraph", jwt, params, "application/x-www-form-urlencoded");

This is my code to get token.

HttpEntity entity = httpRequest("https://homegraph.googleapis.com/v1/devices:reportStateAndNotification", token, params, "application/json");

This is my code to report status.

I want to know if the token is invalid or what is wrong.

In addition, Does this have to do with agentUserId.

{"requestId": "123ABC","agentUserId": "user-123","payload": {
"devices": {
  "states": {
    "light-123": {
      "on": true
    }
  }
}

} }

east
  • 11
  • 1

2 Answers2

0

You need to use your agentUserId in your JSON request - you can retrieve this by using the OAuth Playground tool.

The Account Linking guide also explains how to use this tool for verifying you have properly configured all of your auth tokens.

ToniCorinne
  • 503
  • 3
  • 12
0

Now,I try other way,but I got another bad request.

{"error":"invalid_scope","error_description":"Invalid OAuth scope or ID token audience provided."}, iss: securam-report-state@securam-smart.iam.gserviceaccount.com

I change to user GoogleCredentials

GoogleCredentials creds;
    FileInputStream stream = new FileInputStream("/usr/local/cloud_config/securam-smart-88f8bf5c2792.json");
    creds = GoogleCredentials.fromStream(stream);
    creds.createScoped("https://www.googleapis.com/auth/homegraph");
    creds.refreshIfExpired();
    AccessToken token = creds.getAccessToken();
    return token.getTokenValue();
east
  • 11
  • 1