Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 926
Aakash Gupta Avatar asked Oct 11 '12 12:10

Aakash Gupta


1 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
)
like image 120
Aakash Gupta Avatar answered Sep 20 '22 01:09

Aakash Gupta