GET https: //notify-bot.line.me/oauth/authorize
、POST https://notify-bot.line.me/oauth/token
請自行參閱。POST
方法,需要的Header內容要求,以Python程式碼實現對照如下:
headers = {
"Authorization": "Bearer " + token,
"Content-Type" : "application/x-www-form-urlencoded"
}
message
是必須的,格式為文字,最多1000個字元。即是先前的Python程式碼裡面所用的payload = {'message': msg }
,是必要內容。imageThumbnail
、imageFullsize
是選用的,有最大尺寸限制。imageFile
圖片路徑為選用,支援.png
、.jpg
,權限比imageThumbnail
、imageFullsize
優先。stickerPackageId
、stickerId
為選用,能用的貼圖官方整理於Sticker List,在使用貼圖時這兩個參數都要填,不然會報錯。notificationDisabled
是否關閉用戶通知,預設false。#分享鐵人幫的文+貼圖+縮圖程式
import requests
from bs4 import BeautifulSoup as bs
def lineNotifyMessage(token, msg, img):
headers = {
"Authorization": "Bearer " + token,
"Content-Type" : "application/x-www-form-urlencoded"
}
payload = {
'message': msg,
'imageThumbnail' : img, #imageThumbnail、imageFullsize為成對的圖片,各有尺寸大小
'imageFullsize' : img,
'stickerPackageId' : 2, #stickerPackageId、stickerId為貼圖成對的編號,參閱Line Sticker List
'stickerId' : 520
}
r = requests.post("https://notify-api.line.me/api/notify", headers = headers, params = payload)
return r.status_code
if __name__ == "__main__":
token = '你的權杖內容'
message = '大賢者【告】今日網友梗圖Top1'
url = 'https://memes.tw/wtf' # 爬取https://memes.tw/wtf中網友創作的第一張梗圖
img = bs(requests.get(url).text ,"lxml").find_all("", {'class': 'img-fluid'})[0]['data-src']
lineNotifyMessage(token, message, img)
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing