doukan1258 2015-02-28 04:54
浏览 38

如何从列表中删除具有相同名称的现有日历,并使用php在google calendar api v3中创建和插入事件作为新日历

I am trying to integrate google calender APIv3 using php in my site.The idea is each user have a set of events as per his subscribed package on site on different dates.If the user select a new package later all events from previously subscribed package will overwrite with new one.
For me everything works fine except the following.
1)when a user reached gmail calender rendering page ,for the first time successfully created a calender (eg:My first work as name ) on left menu of My calender list and on that all events are inserted (for eg:events on march1,march5,march8 with different titles)
2)When the user click the link from site to render the same calender for the second time it will again created on left menu My calender list (eg:My first work and My first work two calenders with same name ).All events inserted on previous calender insertion will be there and the second time of insertion to same dates also will be there.(For eg: duplication of events on same dates march1,march5,march8 )
What i want is each time when a user click from site to render the calender page the calender should be created as a new one (this is working) and also the calender with same name on left menu "My calender list" should be deleted.So that there may not be duplicate data/event on same date.

any body please help me to find a solution?
following is my code snippet

$service    = new Google_Service_Calendar($client);
$calendar   = new Google_Service_Calendar_Calendar();
$calendar->setSummary('My first work');
$calendar->setTimeZone( 'Asia/Kolkata');
$createdCalendar        = $service->calendars->insert($calendar);
$calendar               = $service->calendars->get($createdCalendar->getId());
$calendarList           = $service->calendarList->listCalendarList();
foreach($events_data_arr as $key=>$events_data_row)
{
$event = new Google_Service_Calendar_Event();
$event->setSummary($events_data_row['title']);
$event->setLocation('India');

$event->setDescription($events_data_row['description']);

$start = new Google_Service_Calendar_EventDateTime();
$start->setTimeZone('Asia/Kolkata');
$start->setDateTime($events_data_row['start_date'].'T10:00:00.000-07:00');
$event->setStart($start);

$end = new Google_Service_Calendar_EventDateTime();
$end->setTimeZone( 'Asia/Kolkata');
$end->setDateTime($events_data_row['end_date'].'T10:00:00.000-07:01');
$event->setEnd($end);

$createdEvent   = $service->events->insert($createdCalendar->getId(), $event);

}

  • 写回答

1条回答 默认 最新

  • duanpuluan0480 2015-03-09 05:00
    关注

    Following code helped me.

    $calendarList = $service->calendarList->listCalendarList();

    foreach ($calendarList->getItems() as $calendarListEntry) {

    $delid      =   $calendarListEntry->getId();
    $calname    =   $calendarListEntry->getSummary();
    if(strtolower(trim($calname)) == "mycalendername")
    {
        $service->calendarList->delete($delid);
        $service->calendars->delete($delid);
        //echo "ID= ".$delid    ."<br/>";
    }
    

    }

    The idea is to take all calenders from calenderlist using

    $calendarList = $service->calendarList->listCalendarList();

    Afetr that take calender id of those calender which have a name equal to our calender name and delete that calender.Only after this step start creating and inserting to our calender "mycalendername".This will prevent duplicate creation of same calender name to user's main calender list and each time taking our code will create a fresh calender with fresh data

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化