这是我在文档中看到的内容:
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: 在犯了一个愚蠢的逻辑错误之后,它现在可以工作了:)
最佳答案
要发送通知,您必须使用应用程序访问 token - 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/
关于Facebook 通知 - 是否需要许可?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16697025/