2017-07-27 16 views
0

Facebook Messengerのアプリを構築する際に問題があります。 Facebook Messengerに戻ってボタンで「汎用テンプレート」レスポンスを送信しようとすると、次のエラーが表示されます。Facebook Messenger - 無効なキーの種類、ペイロード

{"error":{"message":"(#100) Invalid keys \"type, payload\" were found in param \"name_placeholder[elements][buttons]\".","type":"OAuthException","code":100,"fbtrace_id":""}} 

最も論理的なエラーは、Facebookに間違ったキーを与えたことです。だから私は入力をFacebook docsと比較した。残念ながら私は原因を見つけることができません。

利用可能なログ/データ

データ私はFacebookのに送る:

{"recipient":{"id":"REMOVED_ID"},"message":{"attachment":{"type":"template","payload":{"template_type":"generic","elements":{"0":{"title":"title","image_url":"https://i.ytimg.com/vi/JIciUWPzTxM/hqdefault.jpg","subtitle":"body text","default_action":{"type":"web_url","url":"https://www.google.nl/"}},"buttons":"{\"type\":\"postback\",\"title\":\"Bookmark Item\",\"payload\":\"DEVELOPER_DEFINED_PAYLOAD\"}"}}}}} 

More information

データは、私はFacebookのから受け取っ:

{"error":{"message":"(#100) Invalid keys \"type, payload\" were found in param \"name_placeholder[elements][buttons]\".","type":"OAuthException","code":100,"fbtrace_id":""}} 

提案してください?ペイロードで

+0

が、私はこの質問のための私の受信者ID&fbtrace_idを削除しました。 –

+0

'buttons'の値を文字列として送るのはなぜですか? – CBroe

+0

@CBroe文字列、配列、すべての型のオブジェクトに同じエラーが表示されました。ボタンはオブジェクトでなければなりませんか? –

答えて

0

elementsbuttonsMUSTは配列型でがありますが、それらの両方のためのオブジェクトタイプとして送信されます。

ここあなたです:

{ 
    "recipient": { 
    "id": "REMOVED_ID" 
    }, 
    "message": { 
    "attachment": { 
     "type": "template", 
     "payload": { 
     "template_type": "generic", 
     "elements": { 
      "0": { 
      "title": "title", 
      "image_url": "https:\/\/i.ytimg.com\/vi\/JIciUWPzTxM\/hqdefault.jpg", 
      "subtitle": "body text", 
      "default_action": { 
       "type": "web_url", 
       "url": "https:\/\/www.google.nl\/" 
      } 
      }, 
      "buttons": "{\"type\":\"postback\",\"title\":\"Bookmark Item\",\"payload\":\"DEVELOPER_DEFINED_PAYLOAD\"}" 
     } 
     } 
    } 
    } 
} 

は次のようになります。

サンプルの作業

curl -X POST -H "Content-Type: application/json" -d '{ 
    "recipient":{ 
    "id":"USER_ID" 
    }, 
    "message":{ 
    "attachment":{ 
     "type":"template", 
     "payload":{ 
     "template_type":"generic", 
     "elements":[ 
      { 
      "title":"Welcome to Peter\'s Hats", 
      "image_url":"https://petersfancybrownhats.com/company_image.png", 
      "subtitle":"We\'ve got the right hat for everyone.", 
      "default_action": { 
       "type": "web_url", 
       "url": "https://peterssendreceiveapp.ngrok.io/view?item=103", 
       "messenger_extensions": true, 
       "webview_height_ratio": "tall", 
       "fallback_url": "https://peterssendreceiveapp.ngrok.io/" 
      }, 
      "buttons":[ 
       { 
       "type":"web_url", 
       "url":"https://petersfancybrownhats.com", 
       "title":"View Website" 
       },{ 
       "type":"postback", 
       "title":"Start Chatting", 
       "payload":"DEVELOPER_DEFINED_PAYLOAD" 
       }    
      ]  
      } 
     ] 
     } 
    } 
    } 
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN" 
関連する問題