'Like' a page using Facebook Graph API

Facebook has announced support for liking URL's outside of Facebook by using the official built-in Like action. You need to have publish_actions permissions. The graph url for this is: https://graph.facebook.com/[User FB ID]/og.likes?object=OG_OBJECT_URL&access_token=USER_ACCESS_TOKEN

However, you cannot use this to like a page on Facebook currently, as the documentation states:

For Facebook Pages or websites that do not integrate with Facebook Authentication, developers should continue to use the Like button social plugin.


Update June 2016

It's still not possible to like a page using Facebook API, as stated in the /{user_id}/likes documentation page about Creating/Updating/Deleting:

You can't perform this operation on this endpoint.

In previous versions the message was clearer (see the quote below), but the result is the same: it's not possible.

May 2014

The /{user-id}/likes documentation page States about Publishing Likes of Facebook Pages:

You can't publish using this edge, as it is not possible to like a Facebook Page via any API. You should use the Like Button if you want people to be able to like a page in your app.

This is the most obvious and clear statement that has been able to give me an answer to the question.


if your app is an open graph app, now you can like using the api, and no need for the button anymore.

https://developers.facebook.com/docs/opengraph/actions/builtin/likes/


If you want this functionality in a page tab or canvas page within facebook (say to allow for liking the page from within a likegated page), a work around you can involves what Tom Wells suggested in his reply to Luke. You first embed the iframe version of their like button on your page, and then simply listen for the edge.create event in your JS like so:

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
        // ...
    }
);

In the callback, you can deal with with what happens when the user has liked the page, say like navigating away from the like-gate page, or showing liked-only content.

When the user clicks the iFrame like button, your JS code should receive the edge.create event assuming the iFrame was configured to point to the url of the page in question.