Facebook PHP SDK获取好友列表的速度非常慢

Facebook PHP SDK获取好友列表的速度非常慢,php,facebook-php-sdk,Php,Facebook Php Sdk,使用下面的代码获取好友列表,但给出结果需要很多时间。我如何才能更快地获得结果。有人能帮我解决这个问题吗? 或者有没有其他方法可以让我得到朋友名单 try { $requestFriends = $fb->get('/me/taggable_friends?fields=name&limit=100'); $friends = $requestFriends->getGraphEdge(); } catch(Facebook\Exceptions\Faceboo

使用下面的代码获取好友列表,但给出结果需要很多时间。我如何才能更快地获得结果。有人能帮我解决这个问题吗? 或者有没有其他方法可以让我得到朋友名单

try {
    $requestFriends = $fb->get('/me/taggable_friends?fields=name&limit=100');
    $friends = $requestFriends->getGraphEdge();
} catch(Facebook\Exceptions\FacebookResponseException $e) {

    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

// if have more friends than 100 as we defined the limit above on line no. 68
if ($fb->next($friends)) {
    $allFriends = array();
    $friendsArray = $friends->asArray();
    $allFriends = array_merge($friendsArray, $allFriends);
    while ($friends = $fb->next($friends)) {
        $friendsArray = $friends->asArray();
        $allFriends = array_merge($friendsArray, $allFriends);
        }
    foreach ($allFriends as $key) {
    echo $key['name'] . "<br>"; 

    }
} else {
    $allFriends = $friends->asArray();
    $totalFriends = count($allFriends);
    $counter = 0; 
    foreach ($allFriends as $key) {
        echo $key['name'] . "<br>";
        $counter++;
    }
    echo $counter;

}
试试看{
$requestFriends=$fb->get('/me/taggable_friends?fields=name&limit=100');
$friends=$requestFriends->getGraphEdge();
}捕获(Facebook\Exceptions\FacebookResponseException$e){
//当图形返回错误时
echo“图形返回错误:”。$e->getMessage();
出口
}捕获(Facebook\Exceptions\FacebookSDKException$e){
//验证失败或其他本地问题时
echo“Facebook SDK返回错误:”。$e->getMessage();
出口
}
//如果有超过100个以上的朋友,如我们在第68行定义的限制
如果($fb->next($friends)){
$allFriends=array();
$friendsArray=$friends->asArray();
$allFriends=array\u merge($friendsArray,$allFriends);
while($friends=$fb->next($friends)){
$friendsArray=$friends->asArray();
$allFriends=array\u merge($friendsArray,$allFriends);
}
foreach($allFriends作为$key){
echo$key['name']。“
”; } }否则{ $allFriends=$friends->asArray(); $totalFriends=count($allFriends); $counter=0; foreach($allFriends作为$key){ echo$key['name']。“
”; $counter++; } echo$计数器; }
调试代码,找出是facebook api还是您的代码太慢。如果是facebook api…那么,你无能为力。“慢”对你来说意味着什么?为什么你一次只能得到100个朋友?我不知道API调用的速度有多快,但我猜您在这段代码中的大部分时间都在等待请求返回。你能将限制增加到1000吗?@AmericanUmlaut非常感谢,我更改了代码的限制和小部分,现在速度很快:)@luschn“slow”表示超过2分钟,而且是在更改问题解决之后。无论如何,试图同时获得所有朋友都是个坏主意。最好使用最多100个的限制,并为用户提供一个按钮/链接来加载“下100个朋友”。