douhe5092 2014-04-03 12:28
浏览 117
已采纳

使用php api创建谷歌日历

I want to create a google calendar using php api, is it possible ?

Thanks for your help.

  • 写回答

2条回答 默认 最新

  • doumianfeng6979 2014-04-03 12:40
    关注

    Yes it is possible !

    $url = 'http://www.googleapis.com/calendar/v3/calendars';
    $data = array(
        'summary' => 'MyNewCalendarTitle'
         );
    
    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded
    ",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    
    var_dump($result);
    

    code from this page

    link to doc for Calendar Insert


    But it's way easier to use the Google API PHP client library

    $calendar = new Calendar();
    $calendar->setSummary('calendarSummary');
    $calendar->setTimeZone('America/Los_Angeles');
    
    $createdCalendar = $service->calendars->insert($calendar)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?