Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook notifications - need permission or not?

Here is what I'm seeing in the docs:

Apps can send notifications to any existing user that has authorized the app. No special or extended permission is required.

Okay, sounds good. I'm using the JS SDK and here is what I'm trying to do:

FB.api('/me/notifications?access_token=' + window.accessToken + '&href=test&template=test', function(response) {
        console.log(response);
});

This is what I'm getting:

"(#200) The "manage_notifications" permission is required in order to query the user's notifications."

I have tried replacing the href parameter with my app's real domain. Using my facebook ID instead of "/me/" makes no difference either. HELP!

I HAVE tried adding the manage_notifications permission (and still doesn't work...), but my question is why does it say the opposite in the docs?

EDIT: Went to PHP:

<?php 

include_once('sdk/facebook.php');

$user = $_POST['user'];
$message = $_POST['message'];

$config = array();
$config['appId'] = '609802022365238';
$config['secret'] = '71afdf0dcbb5f00739cfaf4aff4301e7';

$facebook = new Facebook($config);
$facebook->setAccessToken($config['appId'].'|'.$config['secret']);

$href = 'href';

$params = array(
        'href' => $href,
        'template' => $message,
    );


$facebook->api('/' . $user . '/notifications/', 'POST', $params);

?>

EDIT 2: After a silly logic mistake it now works :)

like image 611
Nikolay Dyankov Avatar asked May 22 '13 16:05

Nikolay Dyankov


1 Answers

To send a notification you must use application access token - appid|appsecret, so you should send it server side and execute via AJAX call. PHP example:

require_once("facebook.php");

$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';

$facebook = new Facebook($config);
$facebook->setAccessToken($config['appId'].'|'.$config['secret']);

$user = 'userid';
$message = 'message';
$href = 'href';

$params = array(
        'href' => $href,
        'template' => $message,
    );

$facebook->api('/' . $user . '/notifications/', 'post', $params);

https://developers.facebook.com/docs/concepts/notifications/

like image 107
smalu Avatar answered Nov 01 '22 03:11

smalu