BLOG
LINE Messaging APIを簡単に試してみました
2016/10/11
先日LINEの新APIが公開されていろいろ検証しています。
簡単にcurlを使おうと思いますがいくつか注意点があります。
サンプルcurl
curl -X POST \
-H 'Content-Type:application/json' \
-H 'Authorization: Bearer {ENTER_ACCESS_TOKEN}' \
-d '{
"to": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"messages":[
{
"type": "template",
"altText": "this is a buttons template",
"template": {
"type": "buttons",
"thumbnailImageUrl": "https://example.com/bot/images/image.jpg",
"title": "Menu",
"text": "Please select",
"actions": [
{
"type": "postback",
"label": "Buy",
"data": "action=buy&itemid=123"
},
{
"type": "postback",
"label": "Add to cart",
"data": "action=add&itemid=123"
},
{
"type": "uri",
"label": "View detail",
"uri": "http://example.com/page/123"
}
]
}
}
]
}' https://api.line.me/v2/bot/message/push
・ACCESS TOKENはLINE Developersの管理画面より取得できます。
・LINE Developersの管理画面に設定するWebhook URLはhttps環境を用意しなくてはなりません。
・toは送信先識別子です。
toの調べ方
Webhook URLにアクセス(メッセージを送る)しlogを出力するようにします。
下記はphp出力する例です。
logに出力されているuserIdを使います。
実際これらを使い、curlを叩いて成功すると{}が返ってきます。
そしてメッセージが送信されてきます。