이것은 내 첫 번째 프로젝트는 페이스 북의 API와 페이스 북의 PHP SDK를 사용하여, 기본적으로 모든 사용자 상태를 얻으려고하고있어. 나는 작동해야하는 스크립트를 작성했는데 (최대 실행 시간을 변경하거나 제한 시간 (0)을 설정 했더라도) 500 개의 오류가 발생했지만 내부의 재귀 함수를 사용할 때만 코드를 살펴보십시오.페이 스북 api, 재귀 함수 및 500 오류
내가 기능을 기억 해달라고하면$request = new FacebookRequest(
$session,
'GET',
'/me/statuses'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
$x = $graphObject->getProperty('data');
$y = $x->asArray(); //now i got an array
$paging = $graphObject->getProperty('paging'); // i pick paging with "next" and "prevoiuos "
$paged = $paging->asArray(); //as array
$counter = 0 ;
foreach ($y as $el){
echo ('<h3>'.$y[$counter]->message.'</h3>');
echo "<br/>";
echo "<br/>";
$counter++;
}
$next = $paged['next']; // now i got url for load 20 more statuses
$response = file_get_contents($next); // get content of url
//recoursive function every time i use looper with content of next
function looper($response){
$array = json_decode($response, true);
$secondarray = ($array['data']);
$paging = ($array['paging']); // again i pick url for load next statuses
$next = $paging['next'];// again i pick url for load next statuses
$nextResponse = file_get_contents($next);// again i pick url for load next statuses and i will use this.
$counter2 = 0 ;
foreach ($secondarray as $el){ // put on page next 20 statuses
echo ('<h3>'. $secondarray[$counter2]['message'] .'</h3>');
echo "<br/>";
echo "<br/>";
$counter2++;
}
if (is_null($nextResponse) == false){ // if in next call i got 20 more statuses(not empty) call again this function
looper($nextResponse);
} else { echo "last message" ; die();} //else stop.
}
looper($response);
}
스크립트 잘 작동 20 개 + 20 상태를 인쇄, 다른 사람이 나에게 줄 500 내부 오류 (기본적으로 난 문이 경우 주석). 나는 최대 실행 시간 또는 set_time_limit (0)을 변경하려고했지만 아무 일도 일어나지 않는다고 말했다. 문제가 내 호스팅 (godaddy)인지 또는 스크립트가 좋지 않거나 효율적이지 않은지 잘 모르겠습니다. 어떤 도움? 감사합니다. Nico
당신이 $ nextResponse의 실제 값이 더 옆에 응답이 없을 때 무엇을 볼 수 무한 재귀해야합니다 ... 당신이 –
되고 싶어요 것처럼 null이되지 않을 수도 있습니다 PHP error_log에 어떤 메시지가 있습니까? – angeldelrio
메시지가 없습니다. @angeldelrio –