Thursday, May 31, 2012

"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 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 with a page?


Source: Tips4all

3 comments:

  1. You can't do that. According to the docs you can only like POST it is impossible to like other objects.

    Here is a thread I found on facebook forum:
    http://forum.developers.facebook.net/viewtopic.php?pid=294757

    ReplyDelete
  2. 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

    ReplyDelete
  3. 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.

    ReplyDelete