0

このコードでサーバーエラーログを取得する..また、このコードで81人の友達しか得られませんが、友達リストには87人の友達がいます..

提案をください..

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

1 に答える 1

1

これが役立つかどうかはわかりません。

getloginurl() プロセスで最初に友人データを取得するための拡張許可をユーザーに求める必要があると思います。通常、facebook は通常の許可を得て基本的な情報のみを提供します。

于 2012-08-12T05:47:07.500 に答える