CSRF 状态令牌与提供的令牌不匹配

问题描述 投票:0回答:1

使用此代码获取服务器错误日志..并且此代码只给了我 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;
            }
        }   
      ?>
php facebook facebook-graph-api csrf
1个回答
1
投票

不确定这是否有帮助。

我认为您需要首先在 getloginurl() 过程中向用户请求扩展权限才能获取好友数据。通常,在正常许可的情况下,Facebook 只会向您提供基本信息。

© www.soinside.com 2019 - 2024. All rights reserved.