実現したいこと
問題:event.source.user_idでは情報が取得できない。
課題:BOTがサーバーから退会させられた時に、user_idを取得する。
該当のソースコード
python
1import config 2from flask import Flask, request, abort 3from linebot import ( 4 LineBotApi, WebhookHandler 5) 6from linebot.exceptions import ( 7 InvalidSignatureError 8) 9from linebot.models import ( 10 MessageEvent, TextMessage, TextSendMessage, FollowEvent, LeaveEvent, MemberLeftEvent, UnsendEvent, 11 StickerMessage, StickerSendMessage, 12) 13app = Flask(__name__) 14line_bot_api = LineBotApi(config.LINE_CHANNEL_ACCESS_TOKEN) 15handler = WebhookHandler(config.LINE_CHANNEL_SECRET) 16 17@app.route("/callback", methods=['POST']) 18def callback(): 19 signature = request.headers['X-Line-Signature'] 20 body = request.get_data(as_text=True) 21 app.logger.info("Request body: " + body) 22 try: 23 handler.handle(body, signature) 24 except InvalidSignatureError: 25 print("Invalid signature. Please check your channel access token/channel secret.") 26 abort(400) 27 return 'OK' 28 29@handler.add(LeaveEvent) 30def handle_leave(event): 31 print(event) 32 print(event.source.user_id) 33if __name__ == "__main__": 34 app.run(host="localhost", port=8000) # ポート番号を8000に指定

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/01/08 02:19