我正在向我的应用程序用户发送通知,如下所示:
require_once('php-sdk/facebook.php');
$config = array
(
'appId' => 'blabla',
'secret' => 'blablablabla',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$post = $facebook->api('/'.$user_id.'/notifications/', 'post', array
(
'access_token' => 'blabla|blablablabla',
'href' => 'https://www.my_app_url.net/',
'template' => "You have X new updates waiting on MyAppName !",
'ref' => 'MyApp_notification'
));
现在,如果用户在我的应用上有新的更新但是自上次通知后没有访问过,我会向他发送一个新的通知,其中包含等待他的新更新次数,如果他不这样做,这可能会非常烦人连接一段时间,有50个新的Facebook通知......
所以我的问题是:当我使用PHP API发送新通知时,是否可以删除用户Facebook上的先前通知?
我搜索过但找不到答案......
答案 0 :(得分:1)
我找到了如何将通知标记为已读。
require_once('php-sdk/facebook.php');
$config = array
(
'appId' => 'blabla',
'secret' => 'blablablabla',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
if ($user_id) // Only if the user is connected
{
$permissions = $facebook->api("/me/permissions");
if (array_key_exists('manage_notifications', $permissions['data'][0])) // Check if we have the permission to manage the notifications
{
$access_token = $facebook->getAccessToken();
$get = $facebook->api('/me/notifications?include_read=0&access_token='.$access_token, 'get'); // We get all the unread notifications from the app
for ($i=0; $i<count($get['data']); $i++) // Now let's mark each of them as read
{
$notification_id = $get['data'][$i]['id'];
$facebook->api('/'.$notification_id.'?unread=0&access_token='.$access_token, 'post');
echo 'Mark '.$notification_id.' as read : OK<br>';
}
}
else
{
echo 'err0r: user have not allowed the app to manage his notifications';
}
}
else
{
echo 'err0r: no user connected to the app';
}
似乎没有办法删除一些通知,所以这是我找到的最好的解决方案......希望这可以帮助那些遇到同样问题的人!
以下是我的PasteBin上完整代码的链接:http://pastebin.com/2J0c5L18