开发者

How to present an Unlike link for a Facebook page

I have a Facebook app which is interested in whether users like or unlike specific pages. I want to offer a link to unlike a page, as so far as I know there is no way to unlike a page programmatically using the Graph API.

Facebook provide a like button, but (again, so far as I know) no unlike button. How can I present an option to unlike a page without saying "Click he开发者_开发问答re to go to the page, scroll down to the miniscule unlike link and click it"?


You can issue a DELETE request to the page_id suppose the page id is 1234567890123 place the link as on the a page as:

<a href="unlike.php?d=1234567890123">Unlike</a>

Now collect the GET parameter in the unlike.php file and fire a DELETE request through the graph api:

<?php
$fb = new Facebook(array(
    'appId' => FB_APP_ID,
    'secret' => FB_APP_SECRET,
    'cookie' => true
));

$session = $fb->getSession();

if (empty($session))
{
    $loginUrl = $fb->getLoginUrl();
    echo "<script>window.top.location='{$loginUrl}';</script>";
    exit;
}

$fb_liked_page = $_GET['d']; //COLLECT THE PAGE ID HERE

try
{
    $status = $fb->api("/{$fb_liked_page}/likes", 'DELETE');

    if ($status)
    {
        echo "Success, Unliked!";
    }
    else
    {
        echo "Could not unlike this page.";
    }
}
catch (Exception $e)
{
    var_dump($e);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜