LoginSignup
62
68

More than 5 years have passed since last update.

PythonからLINE NotifyでLINEにメッセージを送る

Last updated at Posted at 2017-03-30

LINE Notifyとは?

LINEが提供するAPIで、システムからメッセージを簡単に送ることができます。
利用にあたっては、事前にトークルームのアクセストークンを発行する必要があります。

詳細は、前回の「Google Apps ScriptからLine NotifyでLINEにメッセージを送る」をご覧ください。

今回は、Python3からメッセージを送る方法になります。
requestsライブラリを使って、画像付きのメッセージを送るサンプルになります。

line_nofity.py
#coding:UTF-8
import requests

def main():
    url = "https://notify-api.line.me/api/notify"
    token = #ここにアクセストークンを入力します。
    headers = {"Authorization" : "Bearer "+ token}

    message =  'ここにメッセージを入れます'
    payload = {"message" :  message}
    files = {"imageFile": open("test.jpg", "rb")} #バイナリで画像ファイルを開きます。対応している形式はPNG/JPEGです。

    r = requests.post(url ,headers = headers ,params=payload, files=files)

if __name__ == '__main__':
    main()

参考URL

62
68
3

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
62
68