For 循环工作不超过 43 次


For loop does not work more than 43 times

我正在运行这个PHP脚本来获取396个Facebook用户的个人资料图片。循环在 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>

您的脚本时间似乎不多了。添加此

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

set_time_limit(0);可能会解决您的问题

您可以使用的另一种技术。请求将一个接一个地完成另一个

页1.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>

页2.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>

http://graph.facebook.com/43给出错误 不支持的获取请求。可能想看看。

某些 ID 没有数据。这是一个单独的问题。

因此,您在这里要做的只是显示Facebook帐户的用户个人资料图片,只需增加循环中的id,而不考虑具有该ID的Facebook帐户是否真的存在......?

您无需在API中查询其个人资料的链接 - 您只需使用数字ID 即可 - https://graph.facebook.com/4/picture 为您提供Mark的个人资料图片,无需先获取他的用户名。