0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Qiitaのアクセス数取得自動化 LINE編④

0
Last updated at Posted at 2026-06-18

データ連携に奮闘中の皆様、いかがお過ごしでしょうか。

本日は、以下LINEの公式ドキュメントを参考にしながら、プッシュメッセージの送信をテストしてみたいと思います。

curl -v -X POST https://api.line.me/v2/bot/message/push \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {channel access token}' \
-d '{
    "to": "U4af4980629...",
    "messages":[
        {
            "type":"text",
            "text":"Hello, world1"
        },
        {
            "type":"text",
            "text":"Hello, world2"
        }
    ]
}'

宛先ですが、まず公式アカウントを作成したアカウントを設定してみたいと思います。
グループに送ろうとするとグループIDなるものが必要なのですが、取得に一手間かかるため、次回以降にいたします。

■LINE個人ユーザへの通知テスト

あらかじめ、送信先のアカウントと公式アカウントを友達にしておく必要があります。

■ユーザIDの取得

1.以下にアクセスし、右上の「コンソールにログイン」を押します。

2.ログインします。

3.ログイン後右上に出ているアカウントのユーザIDを取得します。
image.png

4.作成済の公式アカウントを押します。
image.png

5.チャネル基本設定を下にスクロールします。
image.png

6.「ユーザーID」をコピーして保存します。
image.png

■PowerShell用のコード作成

「channel access token」と「ユーザーID」を既に取得しているので、二か所置き換えて実行すれば、テストできます。

$headers = @{
    "Content-Type" = "application/json"
    "Authorization" = "Bearer {channel access token}"
}
$body = @{
    to = "{ユーザーID}"
    messages = @(
        @{
            type = "text"
            text = "Hello, world1"
        },
        @{
            type = "text"
            text = "Hello, world2"
        }
    )
} | ConvertTo-Json -Depth 10

Invoke-RestMethod -Uri "https://api.line.me/v2/bot/message/push" -Method Post -Headers $headers -Body $body
■メッセージ送信テスト

早速、PowerShellに上記を貼って試してみましょう!
結果はコチラ↓
image.png

レスポンスが返ってきているので、送信できていそうです。

LINEアカウント側も確認します。
公式アカウントの「fukanoshin」からテストメッセージが2件届いています:v:
image.png

次回はグループIDの取得をしていきたいと思います。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?