1

我正在使用可以在用户墙上发布消息的 facebook 应用程序,我的错误消息:

Fatal error: Call to protected method BaseFacebook::getUserAccessToken() from context '' in /home/tillaf/public_html/facebook/login_facebook2.php on line 61

My file :

<?php 

         require_once("facebook.php");

       @session_start();
       $app_id = "********";
       $app_secret = "*********";
       $my_url = "http://t.****.net/**/login.php/";

    ///
       $config = array();
      $config['appId'] = '408682199198463';
      $config['secret'] = 'd5b3c0ddfbd673dd94494f28524c1a84';
      $config['fileUpload'] = false; // optional

        $facebook = new Facebook($config);
       ///

    ////




    ////


      $code = $_REQUEST["code"];

       if(empty($code)) {
         $_SESSION['state'] = md5(uniqid(rand(), TRUE)); // CSRF protection
         $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" 
           . $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
           . $_SESSION['state'] . "&scope=user_birthday,read_stream,publish_stream,email,user_status,offline_access";

         echo("<script> top.location.href='" . $dialog_url . "'</script>");
       }
       else{

         $user_id = $facebook->getUser();
         echo $user_id;
         echo "<br/>";


    ////////// Get Access Token 

    /*
    $app_token_url = "https://graph.facebook.com/oauth/access_token?"
            . "client_id=" . $app_id
            . "&client_secret=" . $app_secret 
            . "&grant_type=client_credentials";

            $response = file_get_contents($app_token_url);
            $params = null;
        parse_str($response, $params);

        echo("This app's access token is: " . $params['access_token']);

    */
    ///-------------

    $user_access_token = $facebook->getUserAccessToken();

    ////////     




         ////// Start publish on wall


         //$facebook->getAccessTokenFromCode($_GET['code']);

         $message='ssss';
         $link='http://www.google.com';
         $name='Samilox';
         $caption='s';
         $description='Descrption...';

        $facebook->api("/me/feed",'POST',
                   array( 'access_token' =>$user_access_token,
                     'message' => 'Hello World!',
                     'link' => 'www.example.com'
                        )
                );
         ///
       }


     ?>

对不起代码:)因为我在发布这个问题之前尝试了很多解决方案。

请问有人可以帮忙吗?提前致谢

4

1 回答 1

1

我修复它使用:

//// 为当前会话添加 AccessToken

  function getAccessToken() {
    if ($this->accessToken !== null) {
      return $this->accessToken;
    }

    $this->setAccessToken($this->getApplicationAccessToken());
    $user_access_token = $this->getUserAccessToken();
    if ($user_access_token) {
      $this->setAccessToken($user_access_token);
    }

    return $this->accessToken;
  }

   function getApplicationAccessToken() {
    return $this->appId.'|'.$this->appSecret;
}

////

于 2012-11-24T14:24:33.100 回答