Send notification to user from app via notification API

I want to send notification from app via notification API to a user who has authenticated my app. Can anyone help me regarding it? Any help will be appreciated.

Lets say, I want user to get a notification when certain events happens in my app

Thanks in advance

Answers


I found its solution myself. Developer need to follow following steps:

  1. Download facebook sdk for php from https://developers.facebook.com/docs/reference/php/
  2. Run following snippet:

Code:

require_once "facebook-php-sdk/facebook.php";

$facebook = new Facebook();

$app_id = YOUR_APP_ID;

$app_secret = YOUR_APP_SECRET;

$app_access_token = $app_id . '|' . $app_secret;

$response = $facebook->api( '/RECEIVER_USER_ID/notifications', 'POST', array(

                'template' => 'You have received a new message.',

                'href' => 'RELATIVE URL',

                'access_token' => $app_access_token
            ) );    

print_r($response);
if everything works fine then you will get following output:
Array

(

    [success] => 1
)

This is an updated code of @Aakash response to this question.

require_once __DIR__ . '/src/Facebook/autoload.php'; // download official fb sdk for php @ https://github.com/facebook/php-graph-sdk
$fb = new Facebook\Facebook([
  'app_id' => '18341642425638', // sample app id
  'app_secret' => '1a8a4037df4d49e5712310c8ad7a62f', // sample app secret
  'default_graph_version' => 'v2.12',
]);

try {
  // Returns a `Facebook\FacebookResponse` object
  $response = $fb->post('/{user_id}/notifications?access_token=1X34XXXXXX25X38|kxXXxxXXXXX3Y&href=&template=@[user_id] Message to display (180 Characters))', 'user_app_token');

} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

var_dump($response);

$response variable should return an array with only one element "success" => 1.

All the necessary variables are available here.

You can try a simulation here and send to yourself notifications.

here the documentation.


Need Your Help

ASP.Net which user account running Web Service on IIS 7?

asp.net web-services iis windows-server-2008

I want to know which account running my Web Service/Application so that I can assign the read/write access to that account. I have researched and see most of the sources mentions about ASPNET accou...