Facebook通知 - 是否需要许可?

时间:2013-05-22 16:28:52

标签: facebook facebook-graph-api facebook-javascript-sdk

以下是我在文档中看到的内容:

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

好的,听起来不错。我正在使用JS SDK,这是我正在尝试做的事情:

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

这就是我得到的:

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

我尝试用我的应用程序的真实域名替换href参数。使用我的Facebook ID代替“/ me /”也没什么区别。帮助!

我已尝试添加manage_notifications权限(但仍无法正常工作......),但我的问题是为什么它在文档中反过来?

编辑:去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);

?>

编辑2:在出现愚蠢的逻辑错误后,它现在可以正常工作:)

1 个答案:

答案 0 :(得分:7)

要发送通知,您必须使用应用程序访问令牌 - appid|appsecret,因此您应该将其发送到服务器端并通过AJAX调用执行。 PHP示例:

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/