Morgan Touverey Quilling
Morgan Touverey Quilling

Reputation: 4333

How to send notifications to an user with PHP?

I searched the Web everywhere to find an answer to my question, but i don't find any clear and simple answer... How to send a notification to an user with PHP ? We consider that the 'user' has installed the FB App.

I tried this code :

$post_data = "access_token=".$facebook->getAccessToken()."&template=My message&href=http://google.com";

$curl = curl_init(); 

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

print($page);

But I receive the following error message : {"error":{"message":"(#15) This method must be called with an app access_token.","type":"OAuthException","code":15}} I don't using the right access_token ?? Thanks to help me or show me another code... :)

Upvotes: 0

Views: 1942

Answers (1)

Anant Dabhi
Anant Dabhi

Reputation: 11104

Try sending notification using this format with access token as querystring

$post_data = "access_token=".$facebook->getAccessToken()."&template=My message&href=http://google.com";

$curl = curl_init(); 

curl_setopt($curl, CURLOPT_URL, "https://graph.facebook.com/".$user."notifications?access_token= … &template= … &href= …"); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$page = curl_exec($curl); 
curl_close($curl); 

print($page);

Upvotes: 3

Related Questions