如何提高Outlook API的响应时间

时间:2014-04-30 07:50:42

标签: php api curl outlook outlook-calendar

我正在使用Outlook Calendar API并且我得到的响应需要花费一分钟时间,这真的很长且令人沮丧,更令人沮丧的是10次中有5次我没有从Calendar API获得结果不确定这是否是由于Calendar API响应缓慢

目前我所做的是发送一个curl请求,如果一切正常我得到了我需要的结果但是如果我收到curl响应中的错误,例如令牌已过期,那么我必须发送另一个curl请求来获取更新的令牌然后第二个curl请求使用更新的令牌

获取记录

这是我的PHP代码

$fields = array(
    'name' => $event_name,
    'description' => $event_desc,
    'start_time' => $meeting_start_time,
    'event_start_time' => $meeting_end_time,
    'access_token' => $token,
    'method' => "POST"
);

$add_new_meeting_url = "https://apis.live.net/v5.0/$live_id/events" . "?" . http_build_query($fields);
$add_new_meeting = curl_init();
curl_setopt($add_new_meeting, CURLOPT_URL, $add_new_meeting_url);
curl_setopt($add_new_meeting, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($add_new_meeting, CURLOPT_CONNECTTIMEOUT, 0);
$get_new_meeting_curl_response = curl_exec($add_new_meeting);
curl_close($add_new_meeting);
$new_event = json_decode($get_new_meeting_curl_response, true);

if ($new_event['error']) {
    $refresh_token_url = "https://login.live.com/oauth20_token.srf?client_id=client_id&client_secret=secret_key&redirect_uri=www.xyz.com&grant_type=refresh_token&refresh_token=$refresh_token";
    $ch_refresh_token = curl_init();
    curl_setopt($ch_refresh_token, CURLOPT_URL, $refresh_token_url);
    curl_setopt($ch_refresh_token, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch_refresh_token, CURLOPT_CONNECTTIMEOUT, 0);
    $get_refresh_token_curl_response = curl_exec($ch_refresh_token);
    curl_close($ch_refresh_token);

    $new_access_token = json_decode($get_refresh_token_curl_response, true);


    $user_id = $adviser_id;
    $params = array(
        ':user_id' => $user_id,
        ':access_token' => $new_access_token['access_token']

    );

    $stmt = parent::query("UPDATE `schedule_access_token` SET `access_token` = :access_token WHERE `user_id` = :user_id;", $params);

    $params = array(':user_id' => $user_id);
    $stmt = parent::query("SELECT * FROM `schedule_access_token` WHERE `user_id` = :user_id;", $params);
    if ($stmt->rowCount() > 0) {
        foreach ($stmt->fetch(PDO::FETCH_ASSOC) as $field => $value) {
            $this->options[$field] = $value;
        }
    }

    $live_id = $this->options['live_id'];
    $token = $this->options['access_token'];
    $refresh_token = $this->options['refresh_token'];
    $user_calendar = $this->options['user_calendar_id'];

    $fields = array(
        'name' => $event_name,
        'description' => $event_desc,
        'start_time' => $meeting_start_time,
        'event_start_time' => $meeting_end_time,
        'access_token' => $token,
        'method' => "POST"
    );

    $add_new_meeting_url = "https://apis.live.net/v5.0/$live_id/events" . "?" . http_build_query($fields);

    $add_new_meeting = curl_init();
    curl_setopt($add_new_meeting, CURLOPT_URL, $add_new_meeting_url);
    curl_setopt($add_new_meeting, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($add_new_meeting, CURLOPT_CONNECTTIMEOUT, 0);
    $get_new_meeting_curl_response = curl_exec($add_new_meeting);
    curl_close($add_new_meeting);
    $new_event = json_decode($get_new_meeting_curl_response, true);

}

由于我完全依赖于API的响应,我能做些什么来加快响应速度?我真的很感激这里的任何帮助,因为这让我发疯了

0 个答案:

没有答案