iT邦幫忙

0

Line Notify如何取得使用者的access token

  • 分享至 

  • xImage

使用語言是python
如標題所寫,我想要在使用者連結notify之後取得使用者的token,但看網路上的教學不是用到postman就是跟linebot做連結的,沒有很了解postman,不過好像都要到網站進行手動操作沒辦法自己回傳,我只是想在資料庫更新時進行通知也不需要用到Linebot那麼複雜
自己上網爬文爬到頭暈眼花也找不出個結果,想請問各位大神有沒有什麼方法可以讓使用者連結後可以自己傳回token,非常感謝

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
0
前端野人
iT邦新手 3 級 ‧ 2022-11-08 23:04:04

https://notify-bot.line.me/doc/en/

用postman 就是測試 API 回傳是否成功 資料長怎樣

在 python 應該就是 兩個非同步的 funcion 而已

看文件應該就是 把參數丟進這隻API就能得到 code 驗證
GET https: //notify-bot.line.me/oauth/authorize

然後再用這隻就能取的 user accesstoken
POST https://notify-bot.line.me/oauth/token

0
科科
iT邦研究生 1 級 ‧ 2022-11-09 09:30:43

我先當作你已經有登入註冊好line notify服務,
並取得Client ID、Client Secret,還有設定好Callback URL:

https://notify-bot.line.me/zh_TW/

程式邏輯如下:

1.你要有個介面提供授權按鈕,讓使用者取得授權連結:

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

2.使用者授權後,會返回你指定的頁面,這時候在取得使用者token

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

3.取得token後,取得使用者資料:

https://notify-api.line.me/api/status

4.將需要儲存的資料存在你設計的資料庫中。

5.要發訊息的時候,到資料庫撈取指定的使用者,利用token發送:

https://notify-api.line.me/api/notify

我自己是寫C#,但邏輯應該都是差不多的,
你再搭配google,看有沒有用python的教學

0
froce
iT邦大師 1 級 ‧ 2022-11-09 09:46:52

line-bot有人包裝好的api。
https://github.com/line/line-bot-sdk-python

因為不知道你的操作場景,如果你是讓人加入你的line-bot的群,用Member join event。
https://developers.line.biz/en/reference/messaging-api/#member-joined-event
看文件應該只能知道目前的群組成員,不能看加入的是誰。
所以你得去跟你的資料庫比對,看誰是新加入的。

另外,這是範例:
https://github.com/line/line-bot-sdk-python/blob/master/examples/flask-echo/app_with_handler.py
你可以把 def message_text(event) 裡的event印出來就知道了。

line-bot加入別的群應該是沒辦法,只能回應。

我要發表回答

立即登入回答