Mapping PSID to FBID
This package allows you to match page-specific id (psid) with user's real id (id starts with 1000...) from webhook events.
Requirement: You must have admin or editor role on that page.
Getting started
This package uses Android or iOS access_token. You can generate one by using this code:
const PsidToFbid = ;const email = "myemail@ngxson.com";const password = "this_is_my_facebook_password"console;
The code will print out an URL. You must access this URL using a browser, on client side, in order to prevent being locked down your facebook account.
The code will return some JSON stuffs. Just find the pattern starts with EAAA...
. That's your access_token.
This action should be done every time you change your password, since facebook will invalidate all your access_tokens.
How to use
npm install psid-to-fbid --save
For example you have a page with id = 182794865548469
, and your Android token is EAAAAUaZA8jlABAIv...
Firstly, you must setup the package like this:
const PsidToFbid = ;const psidToFbid = "182794865548469"psidToFbid
After that, you can use these functions:
getFromWebhookEvent(messaging_event)
Get fbid from messaging_event of webhook
This does NOT work with postback from buttons / Get Started button (but works with quick replies)
Arguments
@param {Object} messaging_event
messaging_event from webhook.@returns {Promise}
Returns Promise resolve(fbid), with fbid = null if there's an error.
Example
app
getFromMid(mid, psid)
Get fbid from mid (message_id)
For example, each time you send a message via /me/messages
endpoint, you receive an object which contains message_id
. The message_id
can then be passed into getFromMid to get fbid of the receiver.
Arguments
@param {String} mid
message_id.@param {String} psid
Optional, user's psid. Used for cache feature.@returns {Promise}
Returns Promise resolve(fbid), with fbid = null if there's an error.
Example
Author
- ngxson (Nui Nguyen)
- Email: contact at ngxson dot com
- My website: https://ngxson.com