Unauthorized Json Response

Since I am not getting accessToken with simulator Request, I did it as said in
https://developers.google.com/actions/identity/account-linking#json
Signin helper request

    header('Content-Type: application/json');
   $askToken = array (
  'conversationToken' => '{"state":null,"data":{}}',
  'expectUserResponse' => true,
  'expectedInputs' => 
  array (
    0 => 
    array (
      'inputPrompt' => 
      array (
        'initialPrompts' => 
        array (
          0 => 
          array (
            'textToSpeech' => 'MY AUTHENTICATION END POINT URL',
          ),
        ),
        'noInputPrompts' => 
        array (
        ),
      ),
      'possibleIntents' => 
      array (
        0 => 
        array (
          'intent' => 'actions.intent.SIGN_IN',
          'inputValueData' => 
          array (
          ),
        ),
      ),
    ),
  ),
);
echo json_encode($askToken);


    exit();

      

I am getting the error

Simulator reaction

"

sharedDebugInfo": [
            {
                "name": "ResponseValidation",
                "subDebugEntry": [
                    {
                        "name": "UnparseableJsonResponse",
                        "debugInfo": "API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: \"expected_inputs[0].possible_intents[0]: Proto field is not repeating, cannot start list.\"."
                    }
                ]
            }
        ]
    },
    "visualResponse": {}
}

      

Mistake

API Version 2: Failed to parse JSON response string with error INVALID_ARGUMENT: \ "expected_inputs [0] .possible_intents [0]: Proto field is not repeated, cannot start with a list. \". "

+3


source to share


1 answer


For starters, this is a pretty good bug report from Simulator. It tells you the exact path in JSON where the error is, so you can use the documentation for the webcam response to see why your JSON might not look like the expected JSON.

In this case, the value for inputValueData

must be a JSON object, not a JSON array. By default, the PHP function json_encode()

assumes empty PHP arrays are empty JSON arrays (and that's the correct assumption for a property noInputPrompts

).

You need to make it be an object. You cannot use the JSON_FORCE_OBJECT option because then it noInputPrompts

will change to an object, which is also wrong.

You need to pass the array to the object using syntax like



(object)array()

      

So your code will look something like

$askToken = array (
  'conversationToken' => '{"state":null,"data":{}}',
  'expectUserResponse' => true,
  'expectedInputs' => 
  array (
    0 => 
    array (
      'inputPrompt' => 
      array (
        'initialPrompts' => 
        array (
          0 => 
          array (
            'textToSpeech' => 'MY AUTHENTICATION END POINT URL',
          ),
        ),
        'noInputPrompts' => 
        array (
        ),
      ),
      'possibleIntents' => 
      array (
        0 => 
        array (
          'intent' => 'actions.intent.SIGN_IN',
          'inputValueData' => 
          (object)array (
          ),
        ),
      ),
    ),
  ),
);
echo json_encode($askToken);

      

+4


source







All Articles