2013-10-06 42 views
0

我正在運行這個PHP腳本來獲取396個Facebook用戶的個人資料照片。 43個結果後循環不起作用。出了什麼問題?請指導。謝謝。For循環不能工作超過43次

<html> 
<head> 
</head> 
<body> 
<?php 
error_reporting (0); 
for ($i = 4; $i <= 400; $i++) 
{ 

      $to_send = "http://graph.facebook.com/"; 
      $to_send_new = $to_send.$i; 
      $content = file_get_contents($to_send_new); 
      $parsed = json_decode($content); 
      $link = $parsed->link; 
      $link = str_replace("http://www.facebook.com","https://graph.facebook.com",$link); 
      $link .="/picture?width=6000&height=6000"; 
?> 
<img src=' <?php echo $link ?>' > 
<br> 
<?php 
} 
?> 
</body> 
</html> 
+0

暫停也許? –

+0

任何錯誤...? –

+0

這可能是某種API調節... – Lix

回答

1

看起來像你的腳本時間已經不多了。收藏此

<?php 
error_reporting (0); 
set_time_limit(0);// Setting an infinite timeout limit. 
+1

這是什麼意見。 – Mark

1

set_time_limit(0);可以解決你的問題

另一種技術可以使用。請求將去一個精加工另一

page1.php中

<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" 
              type="text/javascript"></script> 

<script> 
$(document).ready(function(e) { 
    var i=4; 
    var getResponse = function() { 
     $.ajax({ 
      type:"GET", 
      url:"page2.php", 
      data:{i:i}, 
      async:false, 
      success: function(response) { 
       i++; 
       $("body").append(response); 
       getResponse(); 
      } 
     }); 
    } 
    //setTimeout(getResponse,1000); 
    getResponse(); 
}); 
</script> 
</head> 
<body> 

</body> 
</html> 

使page2.php後

<?php 
error_reporting(0); 
$i = $_GET['i']; 

$to_send = "http://graph.facebook.com/"; 
$to_send_new = $to_send.$i; 
$content = file_get_contents($to_send_new); 
$parsed = json_decode($content); 
$link = $parsed->link; 
$link= str_replace("http://www.facebook.com","https://graph.facebook.com",$link); 
$link .="/picture?width=6000&height=6000"; 
?> 
<img src=' <?php echo $link ?>' > 
<br> 
0

http://graph.facebook.com/43給出錯誤不支持GET請求。可能想看看這個。

某些ID沒有數據。這是一個單獨的問題。

所以你在這裏試圖做的只是顯示Facebook帳戶的用戶個人資料圖片,只需增加您的循環中的ID,而不考慮是否實際存在與該ID的Facebook帳戶...?

你不需要查詢API鏈接到他們的個人資料 - 你可以使用數字ID代替 - https://graph.facebook.com/4/picture爲您提供Mark的個人資料圖片,無需先獲取他的用戶名。