这是我的第一个使用facebook api和facebook PHP sdk的项目,基本上我试图获得所有用户状态。我写了一个应该可以工作的脚本,但是我得到了500错误(即使我改变了最大执行时间或设置了时间限制(0)),但只有当我在里面使用递归函数时,看一下代码:
$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);
}
如果我不记得该功能(基本上我注释掉if语句)脚本工作正常并打印20 + 20状态,否则它给我500内部错误。 正如我所说,我尝试了changin max执行时间或set_time_limit(0),但没有任何反应。 我不确定问题是我的托管(godaddy),还是我的脚本不好/不高效。任何帮助? 谢谢Nico
答案 0 :(得分:0)
我想我发现了你的问题。您将$nextResponse
返回的值设为file_get_contents
。如果无法检索到内容,请参阅http://php.net/manual/es/function.file-get-contents.php它会返回false
。请尝试检查false
而不是null
:
..........
if ( false != $nextResponse ){ // if in next call i got 20 more statuses(not empty) call again this function
looper($nextResponse);
} else { echo "last message" ; die();} //else stop.