I want to check my facebook app's users messages and if someone gets a new message call a function or do something like that in my server. I use PHP Facebook SDK, the code below gets a user's all messages and prints it.
$user_profile = $facebook->api('/USER_ID?fields=inbox','GET');
print_r($user_profile);
But I want to check if one of my fb application's users gets a new message on facebook and get which user got a message? Is it possible?
Unfortunately, not. Thing like this can usually be accomplished with Realtime Updates, where you subscribe to certain fields of the User object (such as "likes", "events", etc) and you will receive a callback from FB when one of these changes. However, not all fields are available for subscription, and it seems that inbox
is one of them.
You can explore your realtime-subscription options through an interactive wizard in developers.facebook.com: https://developers.facebook.com/apps/_INSERT_APP_ID_HERE_/realtime?ref=nav
It looks like your only option is to keep track of the ID of the last message in the last Thread, and keep polling graph's user/inbox endpoint until you see something new. It isn't a good one, but you don't have an alternative.