Facebook API最长执行时间为30秒

时间:2012-03-24 14:50:45

标签: facebook facebook-graph-api

我正在使用脸谱图PHP sdk - 每当我在循环中调用$ facebook-> api方法时我最终会收到此错误

第631行的C:\ wamp \ www \ as \ auth \ facebook \ api \ facebook.php超出了30秒的最长执行时间

这是示例代码

<?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);

    require 'api/facebook.php';

    $facebook = new Facebook(array(
        'appId'  => "53095555325553943",
        'secret' => "231801b76124542642553453cbezz",
        "cookie" => true,
        'fileUpload' => true
    ));

    $user_id = $facebook->getUser();

    if($user_id == 0 || $user_id == "")
    {
        $login_url = $facebook->getLoginUrl(array(
        'redirect_uri'         => "http://apps.facebook.com/rapid-apps/",
        'scope'      => "email,publish_stream,user_hometown,user_location,user_photos,friends_photos,
                    user_photo_video_tags,friends_photo_video_tags,user_videos,video_upload,friends_videos"));

        echo "<script type='text/javascript'>top.location.href = '$login_url';</script>";
        exit();
    }

    //get profile album
    $albums = $facebook->api("/me/albums");
    $album_id = ""; 
    foreach($albums["data"] as $item){
        if($item["type"] == "profile"){
            $album_id = $item["id"];
            break;
        }
    }

    //set photo atributes
    $full_image_path = realpath("Koala.jpg");
    $args = array('message' => 'Uploaded by 4rapiddev.com');
    $args['image'] = '@' . $full_image_path;

    //upload photo to Facebook
    $data = $facebook->api("/{$album_id}/photos", 'post', $args);
    $pictue = $facebook->api('/'.$data['id']);

    $fb_image_link = $pictue['link']."&makeprofile=1";

    //redirect to uploaded photo url and change profile picture
    echo "<script type='text/javascript'>top.location.href = '$fb_image_link';</script>";
?>

2 个答案:

答案 0 :(得分:1)

这不是关于api,这是你的php设置。 您可以在脚本中使用 set_time_limit (使用 set_time_limit(0)进行无限制执行)。 或更改php.ini文件中整个环境的时间限制,更改 max_execution_time 设置

答案 1 :(得分:0)

我认为你应该在facebook.php文件中使用set_time_limit(0)(以及在base_facebook.php中)