Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API - delete like

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?

like image 842
Martin Avatar asked Sep 30 '10 15:09

Martin


People also ask

Is Facebook Graph API deprecated?

Applies to all versions. Facebook Analytics will no longer be available after June 30, 2021. Additionally, we are deprecating the App Dashboard Plugin for Marketing API. For more information visit the Business Help Center.

Is Facebook Graph API RESTful?

Because the Facebook Graph API is a restful JSON API, you can run queries directly in any standard browser; you'd simply be making HTTP calls.

Does Facebook use graph API?

The Graph API is the primary way to get data into and out of the Facebook platform. It's an HTTP-based API that apps can use to programmatically query data, post new stories, manage ads, upload photos, and perform a wide variety of other tasks.

How do I update my graph API on Facebook?

In the App Dashboard Settings > Advanced, scroll to the Upgrade API Version section.


3 Answers

Yes, likes don't have an ID in the Graph API. You like or unlike an item by POSTing or DELETEing to {item_id}/likes, where {item_id} is replaced by the ID of the object you're liking/unliking.

To find out what the current user has liked (so you can delete them appropriately), you can use the "likes" connection of the User object (docs). So, if you request http://graph.facebook.com/me/likes, you'll get a list of pages/people/whatever that a user has liked. (Note: this does not include posts or photos or things like that)

This will return an array of data full of items like this:

{
     "name": "Very Hungry Caterpillar",
     "category": "Artist",
     "id": "29956247793",
     "created_time": "2009-03-27T15:48:29+0000"
}

The ID in there is not the ID of the like. It is the ID of the object that the user has liked, so in order to un-like it, you have to make a DELETE to http://graph.facebook.com/29956247793/likes.

like image 178
cloudfeet Avatar answered Sep 30 '22 18:09

cloudfeet


It's not the 'like' that has an ID, it's the post - which is why the api call uses '/POST_ID/likes' as a target - if you delete '/POST_ID', it'll get rid of the post, but if you delete '/POST_ID/likes' it'll get rid of the user's 'like' for that post.

like image 43
matt lohkamp Avatar answered Sep 30 '22 18:09

matt lohkamp


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.

like image 34
TuomasR Avatar answered Sep 30 '22 19:09

TuomasR