2012-08-11 99 views
0

获取服务器错误日志中记录此代码..而且这段代码给我的只有我的朋友们81,但我有87个朋友在我的好友列表..CSRF状态令牌不匹配一个提供

给我一个建议..

<?php 

    require_once('facebook-php-sdk/src/facebook.php'); 

    $config = array('appId' => 'Your app id','secret' => 'Your app secret',);  

     $facebook = new Facebook($config); 

     $user_id = $facebook->getUser(); 

     if($user_id) { 

      // We have a user ID, so probably a logged in user. 
      // If not, we'll get an exception, which we handle below. 
       try { 
       $access_token = $facebook->getAccessToken(); 




       $usrFrnd_data = array(); 
       $offset = 0; 
       $limit = 5000; 

       //fetch events from Facebook API 


       $user = null;  

       $c = curl_init(); 
       curl_setopt($c, CURLOPT_URL, "https://graph.facebook.com/me/friends/?limit=$limit&offset=$offset&access_token=".$access_token); 
       curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
       curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); 
       curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false); 
       $user = json_decode(curl_exec($c)); 
       curl_close($c); 
       $tmpVar = object2Array($user); 
       $usrFrnd_data = array_merge($usrFrnd_data, $tmpVar["data"]); 

       //loop through pages to return all results 

       while(array_key_exists("next", $tmpVar["paging"])) { 

        $offset += $limit; 
        $c = curl_init(); 
        curl_setopt($c, CURLOPT_URL, "https://graph.facebook.com/me/friends/?limit=$limit&offset=$offset&access_token=".$access_token); 
        curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); 
        curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false); 
        $user = json_decode(curl_exec($c)); 
        curl_close($c); 

        $tmpVar = object2Array($user); 
        // make sure we do not merge with an empty array 
        if (count($tmpVar["data"]) > 0){ 
         $usrFrnd_data = array_merge($usrFrnd_data, $tmpVar["data"]); 
        } else { 
         // if the user entry is empty, we have reached the end, exit the while loop 
         break; 
        } 
       } 

       echo "<pre>"; 
       print_r($usrFrnd_data); 

      }catch(FacebookApiException $e) { 
       // If the user is logged out, you can have a 
       // user ID even though the access token is invalid. 
       // In this case, we'll get an exception, so we'll 
       // just ask the user to login again here. 
       $login_url = $facebook->getLoginUrl(); 
       echo 'Please <a href="' . $login_url . '">login.</a>'; 
       error_log($e->getType()); 
       error_log($e->getMessage()); 
      } 
     } else { 
      // No user, so print a link for the user to login 
      $login_url = $facebook->getLoginUrl(); 
      echo 'Please <a href="' . $login_url . '">login.</a>'; 
     } 

     function object2Array($d){ 
      if (is_object($d)){ 
       $d = get_object_vars($d); 
      } 

      if (is_array($d)) 
      { 
       return array_map(__FUNCTION__, $d); 
      } 
      else 
      { 
       return $d; 
      } 
     } 
     ?> 

回答

1

不确定这会有帮助与否。

我想你需要问问用户在你的getloginurl()过程中首先获得朋友数据的延伸权限。通常脸书只会给你正常的许可基本信息。