[Nodejs] FB Page post comment/reply event engine

岩岩寫左隻FB Page post comment/reply event engine既Nodejs module。

個module目的係幫FB page owner去mon住個FB page係咪有新comment,然後generate event & 俾個位d人自己去寫callback logic。

實際做法就係佢背底會行個schedule job去call FB graph API黎check post既new comments。

NodeJS module for keep track Facebook Page Posts New Comments

NodeJS module “fb-page-comment-event”

This module can keep track your Facebook page posts’ first level comment events. Hence, if someone commented on your post, you will be notified by an event.

This module support running an event-engine which would manage a background schedule job to check new comment and generating events. This module also support raw APIs which you can check new comments and digest as events by yourself via APIs.

 

Related Pages

Github page: https://github.com/airicyu/fb-page-comment-event
NPM: https://www.npmjs.com/package/fb-page-comment-event

 

Description

This module can keep track your Facebook page posts’ first level comment events. Hence, if someone commented on your post, you will be notified by an event.

This module support running an event-engine which would manage a background schedule job to check new comment and generating events. This module also support raw APIs which you can check new comments and digest as events by yourself via APIs.


Running the event engine

You may use the lib.pageCommentEventApp(options) API to get a event engine app and then start it with run function. This event engine app would manage a schedule job to auto pull data.

Sample:

  • Remarks: pageId is the facebook page ID. postId is the facebook page post ID of post which you want to monitor its comment. accessToken is the Facebook page access token(remember to use the long live token) which Facebook page owner can generate in developer dashboard.

Sample console log output:


(DIY) Use the APIs to check new comments and generating events

Sample:


event engine APIs

let app = lib.pageCommentEventApp({accessToken, pullInterval})

Description:

Initializing the event engine app.

parameters:

  • accessToken: The required accessToken(need permission manage_pages) for the API calls.
  • pullInterval: The sleep time(ms) interval between each scheduled page post new comment checking.

return:

The event engine app.

app.registerMonitorPost({pageId, postId})

Description:

Registering a page post which the event engine would tracking for new comments

parameters:

  • pageId: The page ID.
  • postId: The post ID.

app.run(eventsCallback)

Description:

Start running the event engine and register the new-comment-events callback. Once users write new comments, new-comment-events would be fired and handled by the callback.

parameters:

  • eventsCallback: The batch new-comment-events handling function.

app.stop()

Description:

Stop the event engine


DIY APIs

let queryPostCommentAgent = lib.api.getQueryPostCommentAgent(options)

Description:

Initialize a agent for query post comments.

parameters:

  • options: object with attribute accessToken which holding the required accessToken(need permission manage_pages) for the API calls.

return:

The agent object.

let postCommentFetcher = lib.api.getPostCommentFetcher(queryPostCommentAgent)

Description:

Initialize a fetcher for fetching new post comment.

parameters:

  • queryPostCommentAgent: The agent object which come from lib.api.getQueryPostCommentAgent(options)

return:

The fetcher object.

let postCommentObj = await postCommentFetcher.fetch(postObjId, since)

Description:

Use the fetcher object to fetch post object with comments. We can use this API to get all new comments under the target post which those comments are created since the since time.

parameters:

  • postObjId: The post object ID which is in format of ${pageId}_${postId} in Facebook Graph API.
  • since: The timestamp in second

return:

The post object with comments (All comments child objects are new comments).

let postDigestor = lib.api.getPostDigestor();

Description:

Getting a digestor object which can turn the post-comment object from postCommentFetcher.fetch() result into new-comment-events.

return:

The digestor object.

let newCommentEvents = await postDigestor.digest(postWithNewComments)

Description:

Use the digestor object to digest post-comment object into new-comment-events

parameters:

  • postWithNewComments: The post object with attaching new comments.

return:

New comment event objects

[it學術研究] 熱血時報節目like/分享/留言數字之謎

[itdog學術研究][熱血時報節目like/分享/留言數字之謎]
 
從熱血時報網頁上看到《建國神話XXXXXX》的facebook數據,是「Like:1474 分享:1474 留言:34」
由於like及分享的數目永遠一樣,所以我自己都覺得好奇怪,所以我自己就去了驗證一下。
 
從網頁的ajax request上查找到這條GET request:
 
 
這一條request,是熱血時報call facebook的API拿取數據,這數據是來自facebook的。
而其response的結果是:
 

 

 
其response中的1474與34,正正是like/分享及留言的數目。
 
我修改了一下request:
 
 
得出的結果如下:
 

上面的數字解釋:
359: 是熱血時報原本的那個post的like count (哈哈﹑嬲嬲那些不計作like)。
19: 是熱血時報原本的那個post的comment數目。
 
至於1474與34…
 
1474那個就是平時網頁上看到Facebook like button上面的那種”1.4K people like this.”的那個數字。
我在facebook查找一下就可以知道這數字包括了什麼。
 
What makes up the number shown next to my Like button?
The number shown is the sum of:
1) The number of likes of your URL
2) The number of shares of your URL (this includes copy/pasting a link back to Facebook)
3) The number of likes and comments on stories on Facebook about your URL
 
即是原本的post的like及comment,以及這條URL在facebook上有幾多人share,以及這些post所衍生出來的like及comment,所有總數加起來的數字。
所以嚴格來說,那不是真正的「like」數目,也不是真正的「share」數目,而是facebook把所有engagement加起來的數字。
 
至於34個comment,也應該是類似的把share的數目aggregate出來的,至於實際如何計算我就未能在facebook上找到。
我也數不到如何才count到34。
 
另外,我試過share/comment,但無論是private還是public post,數字都沒有update到,所以那些value可能是cached value或Schedule update value。(未必update)
 
—————————————
 
結論:
網頁上like及share及comment的那些數字(1474, 34)是來自facebook,這數字不是假的。
不過熱血時報把那些數字labelled as 「Like:1474 分享:1474 留言:34」,其實某程度上算是有點誤導(可能是programmer之無心之誤)。
 
熱血時報原本的那個post的like及comment數目分別是359及19。(不計再share出去的post所衍生的數字)
嚴格來說,1474是engagment(參考上面)
而like及share的各自數字未能得知,但計埋衍生數字,總like數必定多於359及少於1474。(未必得知實際數目)