duanliao6077 2012-11-20 16:05
浏览 32

谷歌日历错误处理

I'm using V3 of the google calendar api to sync with a calendar in a php based application.

I use this code to delete events on the google calendar.

$delJson = json_decode($service->events->delete('primary', $gcal_id), true);

Everything runs smoothly if the google calendar id is found. However, the entire process STOPS and displays a blank page if there is no match found between $gcal_id and an actual google calendar id.

At the very least, I want the process to continue without coming to complete halt. I imagine the code would logically be something like this but I can't find any documentation on it.

$delJson = json_decode($service->events->delete('primary', $gcal_id), true);

if ($response == error) { continue } 
  • 写回答

1条回答 默认 最新

  • duanlu9816 2013-11-08 14:46
    关注

    I'm surprised this one has not been answered here, or much of anywhere else; I had the same problem and see it has been asked numerous times without much help answering it.

    The V3 PHP api uses exceptions and the one you need to handle for this is probably the same as for an update(), using a Google_Service_Exception similar to below:

    try {
        $cal->events->update($this->calName,$e,$event);
    } catch (Google_Service_Exception $e ) {
        echo "Caught Google_Service_Exception:";
        print_r($e);
    }
    

    Note, if you have a get, update, you'd need to put the try around the get as well as the update. There are several other exception types in the API and presumably those as well can cause uglies for your website's visitors if not handled. Google_Auth_Exception, Google_IO_Exception, Google_Cache_Exception. So maybe best just to put a generic exception catcher around google API code unless you've studied the particular case to be sure you handle various possible errors.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大