开发者

'Like' a page using Facebook Graph API

Using the Graph API I'd like to be able to have an authorized user "like" a page.

I tried posting the following

https://graph.facebook.com/${PAGE_ID}/likes?access_token=${ACCESS_TOKEN}

And I get an HTTP error 500 accompanied by "Invalid post_id parameter" in the JSON response body. Looks like the /likes resource is suited to liking a wall post and not a page. How do I get this to work w开发者_StackOverflow中文版ith a page?


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.


I believe this is not allowed except for specific partner sites, like yelp. The reason is security, you would be able to put some javascript on a page and have everyone that visits that page "Like"ing it without their knowledge.

See How do I "Like" a URL? on the Facebook Platform Developer Forum


You can like an object with its object id using Facebook api using the following piece of code

[FBRequestConnection startForPostWithGraphPath:[NSString stringWithFormat:@"/%@/likes",{object_id}] graphObject:nil completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
   //do you customisation post like here
}];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜