Q&A

Unable to send message from Line API

前提・実現したいこと

I need to send messages to a line user on a particular trigger from my website. I do not need that user to reply. The information that I already have is the LINE ID. I have already added the bot/channel as friend successfully.

  1. Trigger on my webpage is working correctly, but the sending of the message fails.
  2. Unable to verify the Webhook URL.

発生している問題・エラーメッセージ

  1. On trying to send message, we receive error saying there is an issue with the 'To' field. But the 'To' account is active, I can successfully send and receive message from that ID using Line. The issue happens only when using the messaging API. * I found that the 'userid' mentioned in the example is different from the 'LINE ID'. So, how can I get the userid from the LINE id?*
  2. When trying to verify the webhook url, it fails with error code '302 Found' when using the POST method. Using the GET method, the error is '405 Method Not Allowed'.

該当のソースコード

$bot = app('line-bot');

$textMessageBuilder = new \LINE\LINEBot\MessageBuilder\TextMessageBuilder('Hi');
$line_id='userid';
$response = $bot->pushMessage($line_id, $textMessageBuilder);

試したこと

Create line developer account. Create messageing api channel. Implement line message api Reference Link : https://qiita.com/sh-ogawa/items/2238e579d7ee538025a0

補足情報(FW/ツールのバージョンなど)

Php : 7.4 Laravel: 5.8

  • 0
  • 6
  • 286
  • twitter facebook

That line_id is incorrect. It seems set LINE ID (from LINE app). However it should set userId getting from webhook source user object. It also get from LINE Developer Console.

https://developers.line.biz/en/reference/messaging-api/#source-group

  • 1

Hi, Dinson Damien. As Shiraki-san said "userid also get from LINE Developer Console.", you can get your userid via LINE Developer Console. The prefix of userid is "U". Please check it.

Can you try to get your userid from the page and paste it to your source code for test? What will happen?

  • 1

Shiraki-san, thank you for the reply.

I do not have any group. I have a list of LINE ID in my website DB. For example, 'Takako', 'Yuuki', 'Jackson' I want to send a different message to them one by one. For example, Takako: "Hello Takako-san, i am sending you this message because trigger1 event was caught on our website." Yuuki: "Hello Yuuki-san. Can you please check your email" etc.

"However it should set userId getting from webhook source user object."→ I have the LINE ID of Takako, Yuuki and Jackson from LINE app. But, I do not have the userId (which you mentioned) for Takako or Yuuki or Jackson. So, how can I get the userId corresponding to Takako, Yuuki or Jackson?

  • 0

Hi.

Can anyone please help me with the issue of how to get the userid from the Line ID (from the app)?

Thank you.

  • 0

Can anyone please help me?

  • 0

I will try to get my own userid from Line Dev console and report back here.

  • 0
本当によろしいですか? question.vm