【问题标题】:Facebook PHP API : delete a notification previously sent by my appFacebook PHP API:删除我的应用以前发送的通知
【发布时间】:2013-09-30 12:00:20
【问题描述】:

我正在像这样向我的应用程序用户发送通知:

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 上以前的通知?

我已经搜索但找不到答案...

【问题讨论】:

  • 你是对的亚瑟,通知“删除”是一种废话......;)让我为你谷歌=>Answer
  • 我读过一些帖子说可以使用以下方法删除对象:$facebook->api('/OBJECT_ID', 'DELETE'); 但似乎通知不被视为可删除对象。

标签: php facebook api notifications


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    相关资源
    最近更新 更多