How do i unlike a comment which was previously liked using the Graph API?
According to the Graph API docs you can send a DELETE request to /comment_id/likes and that'll clear the like.
You issue a DELETE request to the LIKES endpoint for the Facebook object that you're trying to remove a like from. You need a valid user session access token (or an offline access token) in order to accomplish this. It's also worth noting that you can't like/unlike PAGES on Facebook using this method, that is a process that the user must manually complete (via visiting the page or clicking a like button from their news feed, or even using the like button social widget.)
Below is an example of how to remove a like from an object using the Facebook PHP SDK.
<?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_object = '123123_123123_123123'; //put the object id you want to delete here
try
{
$status = $fb->api("/{$fb_liked_object}/likes", 'DELETE');
if ($status)
{
echo "Success, Unliked!";
}
else
{
echo "Could not unlike this object.";
}
}
catch (Exception $e)
{
var_dump($e);
}