0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

python で linebot を 作る

Posted at

したいこと

・LINEBOTを作る
・メッセージを送るだけ

参考
https://chuna.tech/blog/web-service/LINE/how-to-use-line-messaging-api/

LINE Developer に ログイン
https://developers.line.biz/console/

インスコ

pip install line-bot-sdk

トークンとIDの確認

トークン
Messaging API設定 > チャンネルアクセストークン

自分のユーザーID
チャネル基本設定の一番最下部にある

test.py
from linebot import LineBotApi
from linebot.models import TextSendMessage
from linebot.exceptions import LineBotApiError

CHANNEL_ACCESS_TOKEN = 'your=' #自分のトークンを入れい
USER_ID = 'your' #自分のユーザーIDを入れて下さい

def send_message(text):
  line_bot_api = LineBotApi(CHANNEL_ACCESS_TOKEN)

  try:
      line_bot_api.push_message(USER_ID, TextSendMessage(text=text))
  except LineBotApiError as e:
    print(e.message)

if __name__ == "__main__":
  text = "テストメッセージ" #好きな文章でOKです
  send_message(text)

これで test.py を動かせばメッセージが送られる

OK

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?