Forum Pplware

Versão Completa: Botão like para foto em página do facebook
Está de momento a ver uma versão reduzida do nosso conteúdo. Ver versão completa com o formato adequado.
Estou desesperadamente a tentar colocar um script em PHP que faça LIKE a uma foto de uma página do Facebook.. usando a OPEN GRAPH e SDK PHP do Facebook.

tenho este código para já:

Código:
<?php
    //include "dbc.php";
    require './src/facebook.php';
        $url = (!empty($_SERVER['HTTPS'])) ? 'https://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].$_SERVER['REQUEST_URL'] : 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].$_SERVER['REQUEST_URL'];
        $facebook = new Facebook(array(
          'appId'  => '******',
          '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 = $facebook->getAccessToken();
// $access_token = $_SESSION['user_id'];
//$_SESSION['fb_135669679827333_access_token'];


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

    function GetCH(){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token?client_id=112115512230132&client_secret=ef3d2a30aa9a3f799130565b8391d42dT&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;
    };
    echo "Access_token : ".$access_token;
    $app_access_token = GetCH();  

      if($_GET['postid']){
      $postid = $_GET['postid'];
      echo "test1";
      }else{
      $postid = "ERROR";//'135669679827333_151602784936066';
      }

        if($access_token){
            echo "test2";
     $pageLike = $facebook->api('/'.$postid.'/likes?access_token='.$access_token.'&method=post', 'POST');
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>


    </head>

    <body>


    </body>
    </html>

Tenho 2 erros:

o user_id dá-me sempre 0
e este erro: Uncaught OAuthException: Invalid OAuth access token signature.

Tenho andado em fóruns internacionais e nacionais e ninguém me resolve isto..

Se alguém me poder ajudar agradeço.
URL's de Referência