Search code examples
facebookfacebook-graph-apifacebook-php-sdkphotos

Modify facebook like button


At this moment "like" button works just with facebook groups. I want to implement "like" button to my website and let people to like photos of my site. It is possible to do it? Or how to programically like facebook photos?


Solution

  • You can like any object, including a photo object by issuing a post to its object url, after receiving proper permissions " publish_stream". Deleting the like is same, just issue 'delete' instead of 'post'

    https://developers.facebook.com/docs/reference/api/photo/#likes

    Using php sdk 3.1.1, with user access token you can :

    -----publish like----- this will post a like to the photos like object.

    <?php
    $params = array(
    'access_token' => ''.$access_token.'',
    'method' => 'post'
    );
    $pageLike = $facebook->api('/PhotoID/likes', 'post', $params);
    ?>
    

    -----issue delete----- this will delete a like to the photos like object.

    <?php
    $params = array(
    'access_token' => ''.$access_token.'',
    'method' => 'post'
    );
    $pageLike = $facebook->api('/PhotoID/likes', 'delete', $params);
    ?>