Question: Can you tell me with steps how can I do a like button in my site (php) to like a page photo on facebook?

I know that I have to use the GRAPH API and have to do the POST via HTTP to /likes .. but I dont know how can I do it with PHP code.

Somebody have an example?

Thank you

Answer: 
Fabio here is the php post snippet that i was able to get working. Snippet includes a curl to get application access token and the api post to like an object, in this case a post on my app.

* The Sample post is here: Shows the post to be liked

<https://shawnsspace.com/plugins/TimeLinePost.php?pageid=135669679827333&postid=135669679827333_151602784936066&type=feed&fh=750>

* The Like Page is here: Should Return whether the user likes or not, or login if not connected.
<https://shawnsspace.com/plugins/TheLike.php?postid=135669679827333_151602784936066>

**Getting the Application Access Token.**
-----------------------------------------

```
function GetCH(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT_MS,20000);
if(substr($url,0,8)=='https://'){
    // The following ensures SSL always works. A little detail:
    // SSL does two things at once:
    //  1. it encrypts communication
    //  2. it ensures the target party is who it claims to be.
    // In short, if the following code is allowed, CURL won't check if the 
    // certificate is known and valid, however, it still encrypts communication.
    curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
}
$sendCH = curl_exec($ch);
curl_close($ch);
return $sendCH;
};
$app_access_token = GetCH();   

```

**Looking in url for postid parameter then liking id**
------------------------------------------------------

```
  if($_GET['postid']){
  $postid = $_GET['postid'];
  }else{
  $postid = '135669679827333_151602784936066';
  }

    if($user){
 $pageLike = $facebook->api('/'.$postid.'/likes?access_token='.$access_token.'&method=post', 'POST');
}

```
You can get permissions by building an array of perms for login url. below i am requesting read\_stream,publish\_stream,publish\_actions,offline\_access in the scope for permissions.

NOTE: app access token needed for logout url.

```
    <?php
    $url = (!empty($_SERVER['HTTPS'])) ? 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        require './src/facebook.php';
    $facebook = new Facebook(array(
      'appId'  => 'APPID',
      'secret' => 'APP-SECRET',
      'cookie' => true, // enable optional cookie support
    ));
    $user = $facebook->getUser();
    if ($user) {
      try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');

            //$pageInfo = $facebook->api('/'.$pageid.'?access_token='.$_SESSION['fb_112104298812138_access_token].');
            //$pageInfoUser = $user_profile[id];
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }
    /*  */
    if ($user) {
      $logoutUrl = $facebook->getLogoutUrl();
    } else {
    $params = array(
      scope => 'read_stream,publish_stream,publish_actions,offline_access',
      redirect_uri => $url
    );
      $loginUrl = $facebook->getLoginUrl($params);
    }
    $access_token = $_SESSION['fb_135669679827333_access_token'];

    ?>
<?php
        if(!$user){
    echo ' : <a href="'.$loginUrl.'" target="_self">Login</a>  ';
    }else{
        echo '<a href="'.$logoutUrl.'?'.$app_access_token.'" target="_blank">Logout</a>';
        }
?>

```