views:

158

answers:

2

Hi there, I'm developing an app for Facebook in PHP, part of which lists the user's "likes". I would like to add a link next to each like so that the user can manage their likes by deleting them where they see fit.

Facebook mentions this in their graph api docs: "You can delete a like by issuing a DELETE request to /POST_ID/likes (since likes don't have an ID)." But each like must have an id - how else would you delete it?

Has anyone done this before, any help will be appreciated.

+1  A: 

Likes do have an ID.

If you look at https://graph.facebook.com/me/likes, you will see that the resulting data does contain an ID value for each.

{
   "data": [
      {
         "name": "Audi",
         "category": "Consumer_products",
         "id": "96585976469",
         "created_time": "2010-09-27T15:30:15+0000"
      }
    ]
}

You might want to try the ID's there, I've noticed that the FB API doc sometimes has errors.

Edit: I think this also may be a terminology issue, as what the doc says doesn't have ID's is probably likes to a user post, and these probably don't really have an ID and can be removed by issuing a delete to the POST_ID/likes. Then there's the likes generated by liking pages and/or external websites via the like-button, and these DO have an ID. Confusing, it is.

TuomasR
Thanks TuomasR, I can get the likes as you specify using $likes = $facebook->api('/me/likes'); which returns an object similar to that you have displayed above. I'm wondering what url or fb javascript method would be used to remove a specific like? Maybe the best way to do this is to reverse engineer the like and get the url of the like like so: $likeParams = json_decode(file_get_contents('https://graph.facebook.com/?ids='.$like['id'])); $likeParams->{$like['id']}->link; and then add a like button for each. Here you could choose to unlike the item.
Martin
+1  A: 

You cannot delete or add likes using any API. The ONLY way a user can like or unlike something is by clicking on the like button. I am 100% sure about this, so don't spend too much time trying to figure this out. Sorry for the bad news.

Nathan Totten
Thanks for the info Nathan. I have a work around where I get the user's likes and then using the url of each like I add a like button.
Martin