You are here

Facebook Notification API with PHP SDK

Development
PHP
Other

I have implemented this in a cron job for a contest application to let the existing users know when a new contest has gone online.

More info on this on https://developers.facebook.com/docs/app_notifications/

This is my code:

$facebook = new Facebook(array(
  'appId'  => FB_APP_ID,
  'secret' => FB_APP_SECRET,
  'grant_type' => 'client_credentials'
));
 
$post = $facebook->api('/' . $user['uid'] . '/notifications/', 'post',  array(
  'access_token' => FB_APP_ID.'|'.FB_APP_SECRET,
  'href' => getBaseURL(),  //this does link to the app's root, don't think this actually works, seems to link to the app's canvas page
  'template' => 'Max 180 characters',
  'ref' => 'Notification sent '.$dNow->format("Y-m-d G:i:s") //this is for Facebook's insight
));