Facebook notification system: Is it polling? - facebook

Notification when the user first login, not so hard, just require a database scan, I can deal with that. However, when a friend send a request or comment on profile X, a notification is sent, and almost immediately receive on the other end even when the user X not making any request. Is it polling? Does not feel like it, since the page never refresh itself. It must be something else? Anyone have any idea? maybe Web Push?

Facebook uses long-polling.
While you're on their page, they have a script continually issue requests to a particular URL. Instead of immediately responding, the server handling that URL first waits for a message to come in to its queue, and then sends that message out to the user. If a certain timeout is reached, the server responds without sending a message, and the client-side script makes another request to that URL.
To see this in action, open up Firebug's Net tab while on a Facebook page and wait for a couple minutes. You should see requests that last for a minute and then are followed up with a new request.

I believe they use AJAX/Javascript for that. It would allow the page to get information from the server and display it without reloading the page. You should be able to do this with an AJAX library like JQuery or something similar. As for whether or not Facebook itself does push or poll, I have no idea, but you can get a similar behavior by polling with AJAX.

Related

Facebook Messenger apps repeated calls to webhook complicating my debug procedures

I'm currently developing my fist bot.
When I add a breakpoint somewhere in the code of my bot application, send a message from my Facebook page, and debugger stops at that point, after some seconds the debugger stops at that point again, making the debug procedure very complicated.
I understand this happens since I didn't acknowledge the message was received by returning a status code 200, and for that reason my Facebook Messenger application keeps sending the same request.
Is there a way to set up my Facebook Messenger application so that it only calls my webhook once, or to increase the period of time my webhook is called?
Otherwise, are there any suggestions overcome this?
Only option really is to send the 200 as soon as the webhook receives a message while you are debugging, so that you can step through any of your message processing.

Facebook Messenger Platform - Webhook Subscription

I have followed the steps to setup the Facebook Messenger platform. The verification GET web hook request work perfectly, as does the subscribe but when I submit the chat I keep getting the follow Developer Alert:
Hi Norah,
We've noticed that your Webhooks subscription for callback URL https://{domain}/v1/webhook has not been accepting updates for at least 16 minutes. Please verify that your callback server is functioning so you may continue to receive updates. If you need to update your callback URL, see https://developers.facebook.com/docs/messenger-platform/webhook-reference#webhook_setup
If your callback URL continues to fail to accept updates for 8 hours straight, we will disable your subscription. To reactivate the subscription, make a POST request with the same parameters, and it will be reactivated.
My post request works through POSTMAN.
Please can someone help me! This is driving me nuts!
Do you have logs on your server for that post requests?
Facebook requires you to return status code 200 for the post request, so they know that you successfully received it. When they havent, they try it again and if that still fails after several times, they will give you this alert.
Maybe facebook uses another content-type or message content than you used with postman.
Your server logs should give you more insights about that.
Depending on what Webhook events that you have subscribed for a page, there will be callbacks for those events, and more, on the url you have specified in the Web Hook set up.
If you had subscribed to the message_deliveries event, every time a message is sent, whether from a user to your page or from your page to a user, there is a, maybe more, calllback with a Message Delivered json object. The Webhook Reference has an example of the Message Delivered json object, but no specification or explanation on what the fields mean.
Occasionally I find that an undocumented Read callback is received, sometimes. The undocumented json data for this is like:
{"object":"page",
"entry":[
{
"id":"1722858134648129",
"time":1465407550812,
"messaging":[
{
"sender":{"id":"1131485883560113"},
"recipient":{"id":"1722858134642218"},
"timestamp":1465407550868,
"read":
{
"watermark":1465407548057,
"seq":428
}}]}]}
Essentially, you must code your callback to handle ALL types of json data gracefully, including unknowns, even though you may not be ready to process them further. For those that you are not ready to handle or uninterested in, return nothing with Http status code 204 (in fact every callback should return 204 as the type is void).
If you handle only those types of json data you are interested in, any unexpected json data will most likely raise an exception in whatever language your web callback code is written in and result in a 500 server error returned to Facebook. It is this 500 error that is causing Facebook to make that complaint in your question.

How facebook initializes recent news feed entries instantly?

I am developing a news feed module for my web project. News feed activities (post, filter, etc.) are nearly similar to Facebook. I ve used pagination pattern that initializes news page by page (eg: 20 post for every scroll) when user scrolls the page down (unlimited scrolling).
I wonder how Facebook initializes current news when one of your friends shares a post.
I guess it uses a trigger that sends an ajax request to get if new posts are exist. Using a timer trigger (with javascript timeout function which sends ajax requests every 10 seconds) would not be an effective solution for this problem.
Does anyone have any other trigger advices for me ?
Thanks in Advance.
If you were to monitor the network activity of the home page, you'd see calls to https://pct.channel.facebook.com/pull with some unique parameters attached to it. While watching it you'd see that the calls take a variable length of time, from 1 second to ~60 seconds.
This is referred to as Long-Polling, where the server waits until new information is available to send back a response. Meantime, the HTTP call is held in suspense as though the endpoint is loading. Once the server finds information available, it sends a response with the data, and closes the connection. Then the client re-opens the connection with another HTTP call once it receives data.

Is there a reliable way to record user initiated facebook apprequests?

It seems like the only way to do apprequests from user to user is via a dialogue. It also seem like I would need to do a ajax post with the invite ids to my server to record them happening. It's a bit unreliable.
Is there a way where I can get a list of the requests without needing to do a post?
You can only list pending requests by calling /me/apprequests on the user. Any other requests that were processed, you need to save them at the initial point of the request.

how to send a http post request to server in iphone app?

how do i send device token from my native iphone app with a specific timer request so that after the specified time push notification alert comes to device.
The title of your question and the text of it don't exactly match.
The easiest way to set up a timer request for push is to sign up with a push service provider that offers timed requests (UrbanAirship does but you may also want to check others like iLime or push.io).
The other option is to write a server where you can queue the requests then run a cron job to push them out. Obviously, that'll take more work. To actually post the message, you could use something like ASIHTTPRequest.
You may also want to tell your users not to rely on exact timing. A lot of variables enter into the process especially if user is on WiFi.