0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LINE Messagin API JSONでの注意

Posted at

LINEのMessagingAPIでのJSONの記述方法ではまった

LINE側でMessaginAPIで用意されているAPIに対してJSON文字列を送信した際に、
iOS版のLINEと、Android版のLINEアプリとで動作の挙動が異なっていたので、メモとして。

JSON文字列の定義は厳密に

結論から言うと、ios版のLINEの方が、Android版のLINEよりも、JSONの定義をしっかり判別している。

例えば、数値型のデータをそのまま数値としてセットして
下記のようなJSONを作って送信した場合、
iosは正常に処理できませんでしたと表示されるが、
Androidはよきように解釈して表示してくれる。



{  
   "type":"box",
   "layout":"horizontal",
   "contents":[  
      {  
         "type":"button",
         "action":{  
            "type":"postback",
            "label":250,
            "data":"action=hit&unit_no=250&machine_type=S",
            "displayText":250
         }
      }
   ]
}

SDKでもメッセージを受け付けたAPIでもチェックしない

PHPのSDKではそもそも型チェックなんてしないし、
そのSDK使ってMessaginAPIを叩いてもその時点ではエラーにならないので
動かしてから違いに気づくこととなりました。

あんまり発生しないとは思いますが、備忘録として。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?