建立Page推文Messenger回應流程

aha (Cheng-Yu Lin)
2 min readNov 1, 2017

--

解構

整個private_replies API的功能:

  1. 使用 POST
  2. API URL: https://graph.facebook.com/<version>/, 目前用v2.10
  3. comment_id 結構為<[post_id]_[comment_id]>
  4. endpoint /private_replies
  5. queryString包含access_token與message
  6. 其中access_token 使用從facebook developer APP 在messenger permission拿到的page token,可以參考上面的說明
  7. 記得要去Graph API Explorer 將 這個APP在這頁的read_page_mailbox的權限打開

以下為範例

[POST]https://graph.facebook.com/v2.10/<[post_id]_[comment_id]>/private_replies?access_token=<page token>&message=<msg>

補充

  1. 拿到自己的粉絲團Page-Scoped ID, PSID

參考文件

點下藍色驚嘆號,就可以看見PSID
https://graph.facebook.com/v2.10/<ID>/ids_for_pages?
page=<OPTIONAL_PAGE_ID>
&access_token=<ACCESS_TOKEN>
&appsecret_proof=<APP_SECRET_PROOF>

2. 取得appsecret_proof的方法

以下用python3為實例

import hmac, hashlib
secret_key = b[app secret]
message = b[page token]
hmac.new(secret_key, message, hashlib.sha256).hexdigest()

--

--

aha (Cheng-Yu Lin)

Passionate about reading, gaming, and travel. Using AI to connect the physical & virtual worlds, I enjoy sharing ideas with others. Let's connect!