Facebook PHP API:删除以前由我的应用程序发送的通知
我正在向我的应用程序用户发送通知,如下所示:Facebook PHP API:删除以前由我的应用程序发送的通知,php,facebook,api,notifications,Php,Facebook,Api,Notifications,我正在向我的应用程序用户发送通知,如下所示: require_once('php-sdk/facebook.php'); $config = array ( 'appId' => 'blabla', 'secret' => 'blablablabla', ); $facebook = new Facebook($config); $user_id = $facebook->getUser(); $post = $facebook->api('/'.$use
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上以前的通知?
我已搜索,但找不到答案…我找到了如何将通知标记为已读。
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上完整代码的链接:你说得对,亚瑟,通知“删除”是一种胡说八道<代码>;)让我用谷歌为你搜索一下=>我读过一些帖子,上面说可以用以下方法删除对象:
$facebook->api('/OBJECT_ID','delete')代码>但似乎通知不被视为可删除对象。