파이썬에서 LINE에 알리는 폭속 메모
6924 단어 파이썬LineNotify
LINE Notify 은 토큰을 발행하고 copipe 하는 것만으로 LINE과 순식간에 연계할 수 있어 매우 쉽고 간단하기 때문에, Python에서 LINE에 통지하기 위한 YouTube용 폭속 비망록으로 게재합니다.
LINE측
로그인
페이지 오른쪽 상단의 로그인 버튼에서 이메일 주소와 비밀번호를 입력하여 로그인합니다.

내 페이지로 이동
오른쪽 상단이 로그인에서 LINE 계정의 사용자 이름으로 바뀌므로 클릭하여 내 페이지를 선택합니다.

토큰 발급
맨 아래에 「토큰을 발행한다」라고 하는 버튼이 있으므로 클릭.

토큰 이름과 대상 설정
토큰 이름을 적당히 쓰고 1:1로 LINE Notify에서 알림 받기를 선택하고 발행을 클릭합니다.

발행한 토큰 복사

발행한 액세스 토큰은, 닫으면(자) 두번으로 볼 수 없게 되어 버리므로, 어딘가 메모장등으로 남겨 두면 좋네요.
파이썬 측
아래 코드의 text로 보내고 싶은 메시지 내용과 token의 내용을 방금 발행한 액세스 토큰으로 다시 작성해 실행합니다.
linenotify.py# ライブラリ
import requests
# 送りたい内容
text = 'こんにちは〜!'
# アクセストークン -> LINE Notify ( https://notify-bot.line.me/ja/ ) のサイトからトークンを発行
token = '*******************************************'
# 送信
url = "https://notify-api.line.me/api/notify"
headers = {'Authorization': 'Bearer ' + token}
payload = {'message': text}
requests.post(url, headers=headers, params=payload)
LINE에 알림이 오면 성공입니다.
덤
스탬프도 보내고 싶은 경우
sticker.py# スタンプ送信 https://developers.line.biz/ja/docs/messaging-api/sticker-list/#sticker-definitions
url = "https://notify-api.line.me/api/notify"
headers = {'Authorization': 'Bearer ' + token}
payload = {
'message': text,
'stickerPackageId': 789,
'stickerId': 10855,
}
requests.post(url, headers=headers, params=payload)
스탬프 ID는 여기
htps : //에서 ゔぇぺぺrs. 네. 비 · 자 / 도 cs / 메사 긴 g 아피 / s 치 케 r ぃ st / # s 치 케 케 루로 후 니치 온 s
이미지도 보내고 싶다면
img.py# 画像を保存(Google Colaboratory を使う場合)
from google.colab import files
uploaded_file = files.upload()
# 画像送信
img = '***************.jpg'
files = {'imageFile': open(img, 'rb')}
payload = {
'message': '保存された画像です。',
}
requests.post(url, headers=headers, params=payload, files=files)
Google Colaboratory에서 이미지를 저장할 수 없으면 여기에서 쿠키를 허용하십시오.
chrome://settings/cookies
Reference
이 문제에 관하여(파이썬에서 LINE에 알리는 폭속 메모), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/njn0te/items/76d388330e281f45387e
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
아래 코드의
text로 보내고 싶은 메시지 내용과 token의 내용을 방금 발행한 액세스 토큰으로 다시 작성해 실행합니다.linenotify.py
# ライブラリ
import requests
# 送りたい内容
text = 'こんにちは〜!'
# アクセストークン -> LINE Notify ( https://notify-bot.line.me/ja/ ) のサイトからトークンを発行
token = '*******************************************'
# 送信
url = "https://notify-api.line.me/api/notify"
headers = {'Authorization': 'Bearer ' + token}
payload = {'message': text}
requests.post(url, headers=headers, params=payload)
LINE에 알림이 오면 성공입니다.
덤
스탬프도 보내고 싶은 경우
sticker.py# スタンプ送信 https://developers.line.biz/ja/docs/messaging-api/sticker-list/#sticker-definitions
url = "https://notify-api.line.me/api/notify"
headers = {'Authorization': 'Bearer ' + token}
payload = {
'message': text,
'stickerPackageId': 789,
'stickerId': 10855,
}
requests.post(url, headers=headers, params=payload)
스탬프 ID는 여기
htps : //에서 ゔぇぺぺrs. 네. 비 · 자 / 도 cs / 메사 긴 g 아피 / s 치 케 r ぃ st / # s 치 케 케 루로 후 니치 온 s
이미지도 보내고 싶다면
img.py# 画像を保存(Google Colaboratory を使う場合)
from google.colab import files
uploaded_file = files.upload()
# 画像送信
img = '***************.jpg'
files = {'imageFile': open(img, 'rb')}
payload = {
'message': '保存された画像です。',
}
requests.post(url, headers=headers, params=payload, files=files)
Google Colaboratory에서 이미지를 저장할 수 없으면 여기에서 쿠키를 허용하십시오.
chrome://settings/cookies
Reference
이 문제에 관하여(파이썬에서 LINE에 알리는 폭속 메모), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/njn0te/items/76d388330e281f45387e
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
# スタンプ送信 https://developers.line.biz/ja/docs/messaging-api/sticker-list/#sticker-definitions
url = "https://notify-api.line.me/api/notify"
headers = {'Authorization': 'Bearer ' + token}
payload = {
'message': text,
'stickerPackageId': 789,
'stickerId': 10855,
}
requests.post(url, headers=headers, params=payload)
# 画像を保存(Google Colaboratory を使う場合)
from google.colab import files
uploaded_file = files.upload()
# 画像送信
img = '***************.jpg'
files = {'imageFile': open(img, 'rb')}
payload = {
'message': '保存された画像です。',
}
requests.post(url, headers=headers, params=payload, files=files)
Reference
이 문제에 관하여(파이썬에서 LINE에 알리는 폭속 메모), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/njn0te/items/76d388330e281f45387e텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)