Return to Snippet

Revision: 67381
at September 15, 2014 23:38 by MaRmAR


Initial Code
// Use your APP ID and APP Secret from developer.facebook.com/apps
define("FB_APP_TOKEN", $your_app_id . "|" . $your_app_secret );

/**
 * Send Facebook notification using CURL 
 * @param string $recipientFbid Scoped recipient's FB ID
 * @param string $text Text of notification (<150 chars)
 * @param string $url Relative URL to use when user clicks the notification
 * @return String
 */
function sendNotification($recipientFbid, $text, $url) {
	$href = urlencode($url);
	$post_data = "access_token=". FB_APP_TOKEN ."&template={$text}&href={$href}";

	$curl = curl_init(); 

	curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/v2.1/". $recipientFbid ."/notifications"); 
	curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
	$data = curl_exec($curl); 
	curl_close($curl); 

	return $data;
}

Initial URL


Initial Description
How to post a notification to Facebook's Graph API.

Initial Title
Send Facebook notification

Initial Tags
php, api, facebook

Initial Language
PHP