For循环不能超过43次

时间:2013-10-06 08:00:45

标签: php facebook

我正在运行此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>

3 个答案:

答案 0 :(得分:1)

好像你的脚本时间不多了。添加此

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

答案 1 :(得分: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>

答案 2 :(得分:0)

  
    

http://graph.facebook.com/43提供错误不支持的获取请求。可能想看一下。

  
     

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

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

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