Deleting Objects with Graph API

You have just about every type of data imaginable. You've created and published just about every type of object imaginable. Now how do you remove objects from a user's Facebook profile? How do you let the user undo what he or she just published? How do you “unlike” something that was just liked?

The answer is that you do it just like the GET and POST requests. While GET retrieves objects and relationships between objects, and POST creates and publishes new objects, the HTTP DELETE request deletes and removes objects from a user's profile.

Just like with POST, you can use Curl to send a DELETE command on behalf of the user, or you can just use the library of your choice (like JavaScript and FB.api), sending DELETE as the method type. If you were to do this with Curl, it would look like this:

curl –X 'DELETE'; –F 'access_token=...' https://graph.facebook.com/ID

Of course, you would replace the ... next to access_token with the user's access token and the ID in the Graph API URL with the ID of the object you want to delete.

image Although in most cases, a DELETE actually deletes things, in some cases, such as a like when you send the DELETE for the likes of a post, it unlikes the post. You do this by sending the DELETE method to https://graph.facebook.com/POST_ID/likes (the POST_ID is the ID of the post).

Some libraries don't support the DELETE method. ...

Get Facebook® Application Development For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.