|
import requests
import json
# 你的 LINE Channel Access Token
CHANNEL_ACCESS_TOKEN = 'YOUR_CHANNEL_ACCESS_TOKEN'
# LINE Messaging API 的廣播訊息端點
BROADCAST_API_URL = 'https://api.line.me/v2/bot/message/broadcast'
# 發送廣播訊息的函數
def send_broadcast_message(message):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {CHANNEL_ACCESS_TOKEN}'
}
data = {
"messages": [
{
"type": "text",
"text": message
}
]
}
response = requests.post(BROADCAST_API_URL, headers=headers, data=json.dumps(data))
if response.status_code == 200:
print("廣播訊息已成功發送!")
else:
print(f"發送失敗,狀態碼:{response.status_code}")
print(response.text)
# 使用範例
if __name__ == "__main__":
# 要發送的廣播訊息內容
message = "這是廣播訊息測試!Hello, this is a broadcast message from LINE Messaging API!"
# 發送廣播訊息
send_broadcast_message(message)
|
|