Top Banner
LINE Messaging API 結合LinkIt 7697 檔案連結 https://goo.gl/ JHVgMB CAVEDU 薛皓云
83

LINE Messaging API with LinkIt 7697

Jan 21, 2018

Download

Devices & Hardware

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: LINE Messaging API with LinkIt 7697

LINE Messaging API 結合LinkIt 7697

檔案連結 https://goo.gl/JHVgMB

CAVEDU 薛皓云

Page 2: LINE Messaging API with LinkIt 7697

• Ngrok

–限制每分鐘20筆資料

Page 3: LINE Messaging API with LinkIt 7697

架構

Page 4: LINE Messaging API with LinkIt 7697

Ngrok網站

• Web interface:(主機對外/對內的IP,Port)

• Forwarding(網站->主機對內IP)

Page 5: LINE Messaging API with LinkIt 7697

Python架構

• Argparse:處理內部網域設定

• Flask:簡易的網頁溝通,Default Port:5000

• 參考網頁:http://flask.pocoo.org/docs/0.12/

• https://github.com/pallets/flask

Page 6: LINE Messaging API with LinkIt 7697

• Line-bot API入門參考:https://devdocs.line.me/en/

• API line reply robot:https://devdocs.line.me/en/?python#reply-message

• Line webhook rule:https://devdocs.line.me/en/?python#webhook-event-object

Page 8: LINE Messaging API with LinkIt 7697

登入LINE Business center

• https://business.line.me/zh-hant/

Page 9: LINE Messaging API with LinkIt 7697
Page 10: LINE Messaging API with LinkIt 7697

登入Line

Page 11: LINE Messaging API with LinkIt 7697
Page 12: LINE Messaging API with LinkIt 7697
Page 13: LINE Messaging API with LinkIt 7697
Page 14: LINE Messaging API with LinkIt 7697

透過手機進行用戶確認

Page 15: LINE Messaging API with LinkIt 7697

註冊帳號

Page 16: LINE Messaging API with LinkIt 7697

點選「帳號清單」

Page 17: LINE Messaging API with LinkIt 7697
Page 18: LINE Messaging API with LinkIt 7697
Page 19: LINE Messaging API with LinkIt 7697
Page 20: LINE Messaging API with LinkIt 7697
Page 21: LINE Messaging API with LinkIt 7697

• 輸入名稱

• 上傳圖片

• 選擇業種

Page 22: LINE Messaging API with LinkIt 7697
Page 23: LINE Messaging API with LinkIt 7697
Page 24: LINE Messaging API with LinkIt 7697
Page 25: LINE Messaging API with LinkIt 7697

點擊開始使用API

Page 26: LINE Messaging API with LinkIt 7697
Page 27: LINE Messaging API with LinkIt 7697
Page 28: LINE Messaging API with LinkIt 7697
Page 29: LINE Messaging API with LinkIt 7697
Page 30: LINE Messaging API with LinkIt 7697
Page 31: LINE Messaging API with LinkIt 7697
Page 32: LINE Messaging API with LinkIt 7697

進入LINE developers

Page 33: LINE Messaging API with LinkIt 7697

點選 Channel Secret的SHOW

Page 34: LINE Messaging API with LinkIt 7697

點擊OK

Page 35: LINE Messaging API with LinkIt 7697

取得Channel Secret

Page 36: LINE Messaging API with LinkIt 7697

點選Channel Access Token的ISSUE

Page 37: LINE Messaging API with LinkIt 7697

設定access token的重置時間

Page 38: LINE Messaging API with LinkIt 7697

取得Channel Access Token

Page 39: LINE Messaging API with LinkIt 7697

Python 環境

Windows才需要另外安裝

MAC OSX、Linux(Raspberry Pi)應該都預先裝好了

Page 40: LINE Messaging API with LinkIt 7697

https://www.python.org/

Page 41: LINE Messaging API with LinkIt 7697

點選 Download Python 2.7.13

Page 42: LINE Messaging API with LinkIt 7697

點擊安裝

Page 43: LINE Messaging API with LinkIt 7697
Page 44: LINE Messaging API with LinkIt 7697
Page 45: LINE Messaging API with LinkIt 7697
Page 46: LINE Messaging API with LinkIt 7697
Page 47: LINE Messaging API with LinkIt 7697

PIP 安裝

Python的套件管理器、相當於Node.js的npm

Page 48: LINE Messaging API with LinkIt 7697

• CODE > get-pip.py (或由此下載)

• 透過python執行

Page 49: LINE Messaging API with LinkIt 7697

我的電腦(右鍵)內容

Page 50: LINE Messaging API with LinkIt 7697

點選環境變數

Page 51: LINE Messaging API with LinkIt 7697
Page 52: LINE Messaging API with LinkIt 7697

輸入:; C:\Python27\Scripts

Page 53: LINE Messaging API with LinkIt 7697

開啟CMD

Page 54: LINE Messaging API with LinkIt 7697

• 在cmd下輸入以下:

– pip install line-bot-sdk

– pip install flask

Page 55: LINE Messaging API with LinkIt 7697

Python範例

• 7697研習文件>code>Line>app_with_handler.py

Page 56: LINE Messaging API with LinkIt 7697

更新chn_secret&access token

• #21、22

Page 57: LINE Messaging API with LinkIt 7697

執行(F5)

Page 58: LINE Messaging API with LinkIt 7697

會看到以下訊息

Page 59: LINE Messaging API with LinkIt 7697

將區網公開

Page 60: LINE Messaging API with LinkIt 7697

https://ngrok.com/

Page 61: LINE Messaging API with LinkIt 7697
Page 62: LINE Messaging API with LinkIt 7697
Page 63: LINE Messaging API with LinkIt 7697

執行ngrok

Page 64: LINE Messaging API with LinkIt 7697

cmd輸入: ngrok http 8000

Page 65: LINE Messaging API with LinkIt 7697
Page 66: LINE Messaging API with LinkIt 7697

回到LINE DEVELOPERS

Page 67: LINE Messaging API with LinkIt 7697
Page 68: LINE Messaging API with LinkIt 7697

設定Webhook

• 將NGROK所生成的網址輸入進Webhook URL

–範例https://01a937aa.ngrok.io/callback

–注意要輸入https

Page 69: LINE Messaging API with LinkIt 7697

儲存設定

Page 70: LINE Messaging API with LinkIt 7697
Page 71: LINE Messaging API with LinkIt 7697

跟機器人加好友

Page 72: LINE Messaging API with LinkIt 7697

測試

Page 73: LINE Messaging API with LinkIt 7697

LinkIt 7697開發板設定

Page 74: LINE Messaging API with LinkIt 7697

7697範例

• 7697研習文件codeLineLine_control_led:

• Line_control_led.ino

Page 75: LINE Messaging API with LinkIt 7697

#3 輸入ngrok所生成的網址

Page 76: LINE Messaging API with LinkIt 7697

更新WIFI名稱&密碼#12~13

Page 77: LINE Messaging API with LinkIt 7697

上傳程式並開啟序列埠監控視窗

Page 78: LINE Messaging API with LinkIt 7697

透過LINE機器人控制LED

Page 79: LINE Messaging API with LinkIt 7697

Python範例

Python rule

Flask APIEX:Line開燈,收到開燈

Page 80: LINE Messaging API with LinkIt 7697

Handler處理器

開燈

Flask,回復一個token訊息給Line

Page 81: LINE Messaging API with LinkIt 7697

IP試試看1

• http://127.0.0.1:8000/

Page 82: LINE Messaging API with LinkIt 7697

IP試試看2:POST

• http://127.0.0.1:4040/

Page 83: LINE Messaging API with LinkIt 7697

IP試試看3:GET、POST