像系统一样调试照片

时间:2011-11-05 16:44:31

标签: facebook-graph-api facebook-like facebook-php-sdk photo

我遇到此错误:致命错误:未捕获OAuthException:无效的OAuth访问令牌签名。

我无法获得系统(就像按钮在照片中做的那样(页面照片 - 没有权限要求我猜)工作..有人可以帮帮我吗?

test.php的:

 <?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>


从OP帖子更新,如下:

我已经更改了我的代码,

现在我有了这段代码:

 require_once './src/facebook.php';

class photo_liker {
function __construct()
{
    $this->facebook = new Facebook( array('appId' => fb_appID, 'secret' => fb_secret, 'fileUpload' => true, 'cookie' => true));
}

function postPhotoLike($photoid)
{
    try {
        $args = array('access_token' => $this->facebook->getAccessToken());
        $upload_photo = $this->facebook->api('/' . $photoid . '/likes', 'post', $args);
    } catch (FacebookApiException $e) {
        var_dump($e);
    }

}

function login()
{
    try {
        $uid = $this->facebook->getUser();
    } catch (Exception $e) {
        var_dump($e);
    }

    if($uid) {
        try {
            $user = $this->facebook->api('/me');
        } catch (Exception $e) {
            var_dump($e);
        }

        return true;
    } else {
        $login_url = $this->facebook->getLoginUrl(array('scope' => 'email,publish_stream'));

        ob_clean();
        echo("<script>top.location.href='" . $login_url . "'</script>");
        exit ;
    }
    return false;
}

 }

$test = new photo_liker();
$test->login();
$test->postPhotoLike('103273136379847');

我得到了getUser()== 0 ...我读到这是SDK 3的错误。* ..我该如何解决?

0 个答案:

没有答案