调试照片类系统

发布于 2024-12-14 00:39:56 字数 5116 浏览 2 评论 0原文

我有这个错误:致命错误:未捕获的 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.* ..我该如何解决它?

I have this error: Fatal error: Uncaught OAuthException: Invalid OAuth access token signature.

I can't get the system (like button to do the like in a photo (page photo - no permissions require I guess) work.. Can somebody help me?

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>


Update from OP post, below:

I have changed my code,

Now I have this code:

 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');

I got the getUser() == 0... I read that is a bug of SDK 3.* .. how can I solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文