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.
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
Select "Messaging API Settings" on the tab at the top of the individual channel settings screen.
Click the "Issue Channel Access Token (Long Term)" button at the bottom of the screen to issue the token.
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
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