LoginSignup
1
4

More than 5 years have passed since last update.

LINE Notify

Posted at

概要

LINE Notify を使ってみる。

手順

Line Notify にログイン

https://notify-bot.line.me/en/
image

アクセストークンを取得

image

image

  • 適当な文字列(20文字以下)
  • Notify 通知先の部屋

を入力(選択)

通知を送る

アクセストークンを使って、Post リクエストを発行する。
例えば、次のページ のようにgo を利用して送ってみる。

% cat line.go
package main

import (
    "log"
    "net/http"
    "net/url"
    "strings"
)

func main() {
    accessToken := <access-token>
    msg := "テストメッセージ"

    URL := "https://notify-api.line.me/api/notify"

    u, err := url.ParseRequestURI(URL)
    if err != nil {
        log.Fatal(err)
    }

    c := &http.Client{}

    form := url.Values{}
    form.Add("message", msg)

    body := strings.NewReader(form.Encode())

    req, err := http.NewRequest("POST", u.String(), body)
    if err != nil {
        log.Fatal(err)
    }

    req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
    req.Header.Set("Authorization", "Bearer "+accessToken)

    _, err = c.Do(req)
    if err != nil {
        log.Fatal(err)
    }
}

実行すれば、メッセージが届く

% go run line.go
1
4
2

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
1
4