##やりたいこと
ラズパイからLINEへメッセージ送信
LINE Notifyではなく、特定のアカウント宛にメッセージを送信したい
##困っていること
次のプログラムコードを実行したところ、エラーが発生してしまいました。
エラーの原因が分からず困っております。
'userID'については、Messaging API > Channel情報から得られる Channel IDを設定しています。
userIDとChannel IDは別モノで、これがエラーの原因でしょうか
##エラーコード
text
1Traceback (most recent call last): 2 File "./55_LINE.py", line 12, in <module> 3 line_bot_api.push_message('<1647059599>', TextSendMessage(text='Hello World!')) 4 File "/home/pi/.local/lib/python2.7/site-packages/linebot/api.py", line 140, in push_message 5 '/v2/bot/message/push', data=json.dumps(data), timeout=timeout 6 File "/home/pi/.local/lib/python2.7/site-packages/linebot/api.py", line 996, in _post 7 self.__check_error(response) 8 File "/home/pi/.local/lib/python2.7/site-packages/linebot/api.py", line 1022, in __check_error 9 error=Error.new_from_json_dict(response.json) 10linebot.exceptions.LineBotApiError: LineBotApiError: status_code=400, request_id=5637199d-6396-4962-bbaa-bba30dd28e1d, error_response={"details": [], "message": "The property, 'to', in the request body is invalid (line: -, column: -)"}, headers={'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'Transfer-Encoding': 'chunked', 'expires': '0', 'Connection': 'Keep-Alive', 'Server': 'nginx', 'x-line-request-id': '5637199d-6396-4962-bbaa-bba30dd28e1d', 'pragma': 'no-cache', 'cache-control': 'no-cache, no-store, max-age=0, must-revalidate', 'Date': 'Thu, 05 Mar 2020 00:02:13 GMT', 'x-frame-options': 'DENY', 'Content-Type': 'application/json'}
##プログラムコード
python
1from linebot import LineBotApi 2from linebot.models import TextSendMessage 3 4CHANNEL_ACCESS_TOKEN = 'CHANNEL_ACCESS_TOKEN' 5USER_ID = 'userId' 6 7line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN) 8 9line_bot_api.push_message( 10 USER_ID, 11 TextSendMessage(text='test'))
> userIDとChannel IDは別モノで、これがエラーの原因でしょうか
おそらくそうだと思うのですが、そのuserIDはどのように取得しているのかを記載してみてください。
https://developers.line.biz/en/reference/messaging-api/#send-push-message によれば、ID of the target recipient. Use a userId, groupId, or roomId value returned in a webhook event object. Do not use the LINE ID found on LINE. との記載があります。
ありがとうございます。解決できました。
回答1件
あなたの回答
tips
プレビュー