LoginSignup
51
50

More than 5 years have passed since last update.

LINE Notifyをとりあえず使ってみる

Last updated at Posted at 2016-10-01

LINE Notifyをとりあえずに使ってみる

LINE Notifyにより簡単にLINE通知の実装が可能になったのでpythonで動くプログラムを作ってみた

手順

  1. Line Developerにログイン https://notify-bot.line.me/ja/ 

  2. 画面右上からマイページに行きトークンを発行

3.LINE Notifyアカウントを選択したグループに招待

4.アクセストークンを書き換えプラグラムを実行

python line_notify.py hello

以上

プログラム

※ python2系

line_notify.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
LINE NotifyをPythonから使う
"""

import urllib
import urllib2
import os,sys

url = "https://notify-api.line.me/api/notify"
message = sys.argv[1]
params = {"message":message}
params = urllib.urlencode(params)

req = urllib2.Request(url)
# ヘッダ設定
req.add_header("Authorization","Bearer "+os.environ["LINE_ACCESS_TOKEN"])
# パラメータ設定
req.add_data(params)


res = urllib2.urlopen(req)
r = res.read()
print(r)

curlでもっと簡単に試せる

curl -X POST -H 'Authorization: Bearer <アクセストークン>' -F 'message=<メッセージ>' https://notify-api.line.me/api/notify


参考

LINE Notify公式

https://notify-bot.line.me/ja/

公式ドキュメント

https://notify-bot.line.me/static/pdf/line-notify-api.pdf

51
50
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
51
50