程式開發

用 Google App Script 和 LINE Notify 製作一個每日通知的機器人‧外傳

前幾天就有考慮把它拓展成訂閱式的,今天目標告一段落,就回來動工。 很快地建立另一個 App,包含 storeToken、getTokens、send 以及處理請求的 doGet。

本記在這:https://limaois.me/archives/55
 研究了一下 LINE-Notify,首先會要求提供 Callback URL,接著將使用者導引到

https://notify-bot.line.me/oauth/authorize
?response_type=code
&client_id=your_client_id
&redirecturi=yourcallback_url
&scope=notify
&state=a_hash

其中 your_redirect_url 要與 Callback URL 一致,your_client_id 則登錄後會取得,state 用於防止 CSRF(跨站偽造請求),不過想不太到要怎麼驗證,所以姑且略過之。
當使用者進到這個網址會出現選擇聊天室的介面,選擇後會再把使用者導引到

http(s)://your_redirect_url
?code=user’s_code
?state=a_hash

得到 user’s_code 後,再發送 POST 請求到

https://notify-bot.line.me/oauth/token

並附帶

grant_type=authorization_code
redirect_uri=your_callback_url
client_id=your_client_id
client_secret=your_client_secret
code=user’s_code 

便會回傳 access_token,然後依照上篇處理即可。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *