# **2021/08/09 (LINE Notify)** ###### tags: `藍柏婷` ###### tags: `2021/08/09` ### [**== LINE Notify 入門到進階應用(4) --- 傳送文字網路圖片到Line Notify (Python) ==**](http://white5168.blogspot.com/2017/01/line-notify-4-line-notify.html) :::info **記得安裝 requests** ``` $ python -m pip install requests ``` ::: **程式碼** ```python import requests def SendMessageToLineNotify(message, pic): Token = "WWjgIOXkPZq7RrRGwIUnru3ivMPwqc1g3EMT1Ryo7lx" # 你的權杖 url = "https://notify-api.line.me/api/notify" # 跑不出來的某網站 payload = {'message':message, # 文字 'imageThumbnail':pic, 'imageFullsize':pic, # 圖片 # imageThumbnail、imageFullsize為成對的圖片,各有尺寸大小 'stickerPackageId':446, 'stickerId':1988 # 貼圖 # stickerPackageId、stickerId為貼圖成對的編號 # 可參見Line Sticker List總表 https://developers.line.biz/en/docs/messaging-api/sticker-list/#sticker-definitions } # 要傳送的訊息 header = {'Content-Type':'application/x-www-form-urlencoded', # 在 HTTP 中有兩種 POST 數據的方式:application/x-www-form-urlencoded和multipart/form-data。 # 如果您要傳輸二進制(非字母數字)數據(或非常大的有效負載),請使用multipart/form-data。 # 否則,請使用application/x-www-form-urlencoded。 'Authorization':'Bearer ' + Token # 根據使用者的角色來授予應有的權限 # 不要手殘把'Bearer '中的空格弄掉!!!會出事!!! } # 自訂請求表投 r=requests.post(url, headers=header, data=payload) # 將文字、照片、貼圖傳送出去 print(r.text) # 回傳" {"status":200,"message":"ok"} "的指示(.text可以查看資料) def main(): message = '小雞好可愛' # 提示文字 pic = 'https://imgcdn.cna.com.tw/www/WebPhotos/800/20210427/1920x1280_581754849593.jpg' # 圖片 SendMessageToLineNotify(message, pic) if __name__ == '__main__': # 可避免電腦將引用之程式的主程式也一併執行 main() ```  **顯示 `{"status":200,"message":"ok"}` 代表傳送成功** **關於程式碼,https://notify-bot.line.me/doc/en/ 及 https://ithelp.ithome.com.tw/articles/10234576 中有指令的詳細介紹** **Response** | Response header | Value | | --------------- | ------------------------------------ | | Status | 200: Success | | Status | 400: Bad request | | Status | Other: Processed over time or stopped|  
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up