サイトを参考に以下のコードをコピーしました。
<?php require_once __DIR__ . '/vendor/autoload.php'; $httpClient = new \LINE\LINEBot\HTTPClient\CurlHTTPClient(getenv('CHANNEL_ACCESS_TOKEN')); $bot = new \LINE\LINEBot($httpClient, ['channelSecret' => getenv('CHANNEL_SECRET')]); $signature = $_SERVER["HTTP_" . \LINE\LINEBot\Constant\HTTPHeader::LINE_SIGNATURE]; try { $events = $bot->parseEventRequest(file_get_contents('php://input'), $signature); } catch(\LINE\LINEBot\Exception\InvalidSignatureException $e) { error_log("parseEventRequest failed. InvalidSignatureException => ".var_export($e, true)); } catch(\LINE\LINEBot\Exception\UnknownEventTypeException $e) { error_log("parseEventRequest failed. UnknownEventTypeException => ".var_export($e, true)); } catch(\LINE\LINEBot\Exception\UnknownMessageTypeException $e) { error_log("parseEventRequest failed. UnknownMessageTypeException => ".var_export($e, true)); } catch(\LINE\LINEBot\Exception\InvalidEventRequestException $e) { error_log("parseEventRequest failed. InvalidEventRequestException => ".var_export($e, true)); } foreach ($events as $event) { if (!($event instanceof \LINE\LINEBot\Event\MessageEvent)) { error_log('Non message event has come'); continue; } if (!($event instanceof \LINE\LINEBot\Event\MessageEvent\TextMessage)) { error_log('Non text message has come'); continue; } $bot->replyText($event->getReplyToken(), $event->getText()); } ?>しかし
2017-07-12T09:11:16.256817+00:00 app[web.1]: [12-Jul-2017 09:11:16 UTC] PHP Warn
ing: Invalid argument supplied for foreach() in /app/index.php on line 20
が出てしまい、$eventが配列じゃないから処理ができないのかなと思い
(array)$eventでとりあえず、処理を通そうとしました。
すると、
2017-07-12T09:12:12.142885+00:00 app[web.1]: [12-Jul-2017 09:12:12 UTC] parseEve
ntRequest failed. InvalidSignatureException => LINE\LINEBot\Exception\InvalidSig
natureException
とエクセプションを吐いて処理ができません。
LINEAPIは初めて触るのですが
オウム返しを行いたいだけです。
ちなみに、ログを確認しましたが
入力した文字は受け取れています。
どなたかご教授のほどよろしくお願いします。
あなたの回答
tips
プレビュー