2012-11-18 85 views
1

我使用的Facebook應用程序可以在用戶牆發佈消息,我的錯誤消息:調用getUserAccessToken()返回錯誤

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


    ?> 

對不起代碼:)因爲我想很多解決方案之前,我張貼了這個問題。

請誰能幫助? 在此先感謝

+0

這種方法並不意味着可以直接調用,但僅限於SDK的基類本身。你想用這種方法解決什麼_problem_? – CBroe

+0

我需要獲得當前用戶令牌訪問。 –

+0

使用'的Facebook :: getAccessToken()'爲。這給出SDK正在使用的當前令牌 - 所以您必須先讓用戶正確授權。 – CBroe

回答

1

我固定它使用:

////添加的accessToken爲CURREN會議

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; 
} 

////