9
7

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 3 years have passed since last update.

LineNotifyを使ってメッセージ、画像を送信する

Last updated at Posted at 2020-03-22

#LineNotifyを使って Fortniteの画像とメッセージを送ってみる。
まず、LINE Notifyのサイトでログインしてトークンを発行する。
https://notify-bot.line.me/ja/

・Mac
・python

(1)ディレクトリ構成
imagesの中に、gazo.jpegを保存。

test
├test.py
└images
  └gazo.img

(2)test.pyを記述
コードは以下の通り。

test.py
#coding:UTF-8
import requests,os



#------画像を送る場合----------------------------
def main_gazo():
    url = "https://notify-api.line.me/api/notify"
    token = "*********************************"
    headers = {"Authorization" : "Bearer "+ token}

    message = 'Fortnite!'
    payload = {"message" :  message}
    #imagesフォルダの中のgazo.jpg
    files = {"imageFile":open('images/gazo.jpeg','rb')}
  #rbはバイナリファイルを読み込む
    post = requests.post(url ,headers = headers ,params=payload,files=files)


#------メッセージを送る場合----------------------------
def main():
    url = "https://notify-api.line.me/api/notify"
    token = "*********************************"
    headers = {"Authorization" : "Bearer "+ token}

    message = 'Fortnite!'
    payload = {"message" :  message}

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


if __name__ == '__main__':
    main_gazo()#画像を送るmain_gazo()を動かしてみる(メッセージの場合はmain())
9
7
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
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?