2017-07-27 23 views
3

私はエラー解析できないJSONレスポンス

を取得
https://developers.google.com/actions/identity/account-linking#json
リクエストサインインヘルパーを

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(); 

に言ったように私は上記をしたシミュレータリクエストでaccessTokenを取得しておりませんのでシミュレータの応答

" 

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": {} 
} 

エラー

APIバージョン2: '例外Invalid_argument' エラーでJSONレスポンス文字列を解析できませんでした:\。 "expected_inputs [0] .possible_intents [0]:プロトフィールドが繰り返されていない、リストを開始することはできません\"」

答えて

4

初心者の方は、シミュレータからのエラーメッセージがかなり良いです。これはJSONのどこにエラーがあるかを正確に伝えるため、the webhook responseのドキュメントを使用してJSONが期待されるJSONのように見えない理由を追跡できます。

この場合、inputValueDataの値は、JSONオブジェクトでなくJSONオブジェクトである必要があります。デフォルトでPHPのjson_encode()関数は空のPHP配列が空のJSON配列であると仮定しています(これはnoInputPromptsプロパティの正しい仮定です)。

強制的にオブジェクトにする必要があります。 は、noInputPromptsがオブジェクトに変更されるため、JSON_FORCE_OBJECT設定を使用できませんが、これも間違っています。

あなたはだからあなたのコードがそれを指摘するためにありがとう
+0

$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); 

ようになり、このような

(object)array() 

ような構文を使用して、オブジェクトに配列をキャストする必要が

! :) – Elo97234c

+0

私はそれをやった後、私はちょうど '申し訳ありませんが、私は応答を得ていない。 – Elo97234c

+0

ドキュメントのhttps://developers.google.com/actions/identity/account-linking#jsonには、PLACEHOLDER_FOR_SIGN_INというものがあります。それは私の認証エンドポイントのURLであるはずですか? – Elo97234c

関連する問題