Facebook-chat-api: Read notifications of Facebook profile?

Created on 19 May 2018  路  3Comments  路  Source: Schmavery/facebook-chat-api

Hi, everyone!

I was playing around with this great library, and I was trying to list notifications of a Facebook profile (not Messenger).

First, i don't know if this library is intended for that, but it seems to work and I would love to use it for a personal application that informs me about notifications in more than one account in same browser (shhh, don't let they know).

What did I do? Step-by-step

  • Install the module or clone this repo;
  • Add a file module/src/getNotificationList.js and copy from getThreadList.js;
  • Register it in index.js;
  • Remove all argument checks, and all arguments, except callback;
  • Call defaultFuncs.post with our form (I cleared the form and added only the "data" and "__a" field, see below for details);
  • Make a test file with the first example in the docs, but replace the listen function call by our method;
  • Run the test and get the answer. Do not look for the payload as the getThreadList do, but get the whole answer and look for a jsmods field.

What is wrong?
I got the answer, it's a JSON, it's OK, but it's pretty different from what I get in the browser! In Firefox I get all the fields with the notifications, but in Node I get an incomplete answer. The field with the notifications is missing.

What is the request that works in browsers?
With a logged account, access this link.
The link is composed by:

  • the URL of facebook.com;
  • the URI to ajax/pagelet/generic.php/WebNotificationsPayloadPagelet
  • a data JSON with {businessUserID, length, clientRequestID};
  • and a __a field.

The fields are OK, but you must send the cookies too. Because of that, I tried to use the post function matching what getThreadList did.
In Firefox, for example, I can find (Ctrl+F) for the text of my last notifications, but they do not appear on Node.

So what I want is to receive the same JSON as I received in Firefox, so I can access response.jsmods.require[0][3][2].nodes array (this index will be resolved programatically, not hard-coded) and get the information about the last notifications in the profile.

Any hint of what is going on? Did the link worked to you?

Most helpful comment

"I get an incomplete answer" sometimes facebook uses two requests for some things. eg. one requests gives you some list of things, with basic info, and another request (where you tell them what you want) gives you full info

All 3 comments

Cool stuff!
So you'll need to really replicate the request the browser makes, down to all the headers, all the query parameters and all data you send as body (when it's a POST).
You said you cleared the form, make sure you didn't remove anything, because those might be used (well you never know).
You'll also need to make the correct type of request GET/POST.
We automatically attach the cookies if you use the defaultFunc.
There might be other cookies we are not sending, check the request the browser makes!

Finally, maybe the nodejs instance tells FB that it's a different browser than yours, which might influence how it responds to your request. Try matching the browser versions also by tweaking the headers in the post function function in utils.js.

"I get an incomplete answer" sometimes facebook uses two requests for some things. eg. one requests gives you some list of things, with basic info, and another request (where you tell them what you want) gives you full info

Thank you both! It's working now 馃槂 .
It is simple and get only the last notifications (no "cursor" for now), and it is not for Messenger, then I don't know if they will want to include the function in the package in this state, but I think I will format the code and try to open a pull request anyway.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KuoyuanY picture KuoyuanY  路  7Comments

ido43210 picture ido43210  路  4Comments

DanH42 picture DanH42  路  3Comments

Dinamots picture Dinamots  路  8Comments

thaspoom picture thaspoom  路  5Comments