Broadcast on LINE using python

Introduction

Since the information was broadcast from the system on LINE, I will leave the procedure at that time.

LINE has separate LINE @ and LINE official accounts, but they seem to have been integrated. You can create an account for free, and you can only register with your email address. LINE has several APIs, but we will use the Messaging API for mass distribution. Up to 1000 messages can be distributed for free on one channel, so I think you can fully test it.

Channel creation

First, click Create Business Account from this URL, and then click Create with Email Address. https://account.line.biz/login

Then log in with the business account you created and create a provider and channel. https://developers.line.biz/ja/docs/messaging-api/getting-started/#using-oa-manager

Channel access token issuance

Select "Messaging API Settings" on the tab at the top of the individual channel settings screen.

スクリーンショット 2020-11-15 14.36.40.png

Click the "Issue Channel Access Token (Long Term)" button at the bottom of the screen to issue the token.

スクリーンショット 2020-11-15 14.38.30.png

Program execution

You can deliver it by executing the program below. Please use the access token issued earlier by setting it in a variable.

test_delivery.py


# -*- coding:utf-8 -*-
import requests
import urllib.request, urllib.error
import json

url = 'https://api.line.me/v2/bot/message/broadcast'
channel_access_token = 'Created channel_access_token'
#Data for transmission
#type in message,You can send multiple messages at once by adding an array of text.(Maximum number 5)
data = {
    'messages' : [{
        'type':'text',
        'text':'Text you want to deliver'
    }]
}
jsonstr = json.dumps(data).encode('ascii')
request = urllib.request.Request(url, data=jsonstr)
request.add_header('Content-Type', 'application/json')
request.add_header('Authorization', 'Bearer ' + channel_access_token)
request.get_method = lambda: 'POST'
#Send execution(If the response is 200, the transmission is successful.)
response = urllib.request.urlopen(request)

The formula is easy to understand for detailed usage. https://developers.line.biz/ja/reference/messaging-api/#send-broadcast-message

Finally

I used the LINE Messaging API for the first time and it was easy to understand and very easy to use. There are also webhooks and OAuth, so I'll try them when I have time. Please point out any mistakes in this article.

Recommended Posts

Broadcast on LINE using python
Introducing Python using pyenv on Ubuntu 20.04
Notes on using MeCab from Python
Preparing python using vscode on ubuntu
Study on Tokyo Rent Using Python (3-2)
Notes on installing Python using PyEnv
Notes on using rstrip with python.
Install Python on CentOS using Pyenv
Study on Tokyo Rent Using Python (3-3)
Install Python on CentOS using pyenv
Notes for using OpenCV on Windows10 Python 3.8.3.
Execute Python code on C ++ (using Boost.Python)
Detect "brightness" using python on Raspberry Pi 3!
Python on Windows
twitter on python3
Install python library on Lambda using [/ tmp]
Start using Python
python on mac
LINE heroku python
Run servomotor on Raspberry Pi 3 using python
Study on Tokyo Rent Using Python (3-1 of 3)
Python on Windbg
Detect temperature using python on Raspberry Pi 3!
Video processing using Python + OpenCV on Mac
Scraping using Python
Notes on using code formatter in Python
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Detect slide switches using python on Raspberry Pi 3!
Notes on installing Python3 and using pip on Windows7
Install Python 3.8.6 on macOS Big Sur using pyenv
Python: Try using the UI on Pythonista 3 on iPad
Python development on Ubuntu on AWS EC2 (using JupyterLab)
Detect magnet switches using python on Raspberry Pi 3!
Notes on using dict in python [Competition Pro]
Syntax highlighting on the command line using Pygments
My thoughts on python2.6 command line app template
Sound the buzzer using python on Raspberry Pi 3!
Operate Route53 on the command line using AWS-CLI.
[Python] Notes on accelerating genetic algorithms using multiprocessing
Python conda on cygwin
Install python on WSL
Operate Redmine using Python Redmine
PyOpenGL setup on Python 3
Install Scrapy on python3
Install Python on Mac
Install Python 3 on Mac
Install Python3.4 on CentOS 6.6
Data cleaning using Python
Installing pandas on python2.6
python basic on windows ②
WiringPi-SPI communication using Python
Install python on windows
Age calculation using python
Install Python 2.7.3 on CentOS 5.4
Search Twitter using Python
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
Name identification using python
Notes using Python subprocesses
Notes on using Alembic