2013-01-07 139 views
5

嗨我想创建一个事件在谷歌日历在谷歌日历API在谷歌日历如何使用android使用日历API在Google日历上添加事件?

我已经创建了一个由Google提供的示例项目,并且我遵循了每个步骤并成功编译了项目。

但是在这个Google日历的例子中,我只能为我的Google日历帐户创建一个日历名称,我不能创建任何事件。

有什么办法在Google日历中创建事件吗?如果是这样,我该怎么做?

回答

2

搜索了一段时间后,我终于找到了解决办法.the答案是在谷歌文档它的自我只是经过this link

它显示了如何创建使用谷歌API压延机的事件。

+0

hiii can u plz send me code or tell how how to add event in google calendar from或应用程序在background.i想添加事件,而我从我的习惯日历中选择一个日期。然后我可以看到,在我的登录日历谷歌日历默认evnet – Google

+1

hiii可以üPLZ告诉我如何添加事件在谷歌日历没有打开弹出窗口..我无法理解文档。我完成了make api并在google account中添加了密钥。但是不知道如何添加事件告诉我plz? – Google

+0

只需下载代码中的源代码只需要通过代码 – Ramz

2

这是一个巨大的痛苦在屁股 - 但我终于得到它的工作至少创造事件。

下载最新的Google PHP API zip,并将其上传到Web服务器上的includes文件夹。使用Google API Console设置API客户端。确保你将你的重定向网址设置为与你网页的网址相同 - 所以它重定向到它自己。

我最初只是为事件细节设置了一些变量,你可以制作一个表格,如果你想要的话就把它们推进去。

这里是我的代码:

<?php 
    $jobname = "BINGO"; 
    $joblocation = "Your mums house"; 
    $jobdescription = "An interview with a dog."; 
    $startofjob = "2013-12-20T17:00:00.000+00:00"; //datetimes must be in this format 
    $endofjob = "2013-12-20T18:00:00.000+00:00"; // YYYY-MM-DDTHH:MM:SS.MMM+HH:MM 
    //So that's year, month, day, the letter T, hours, minutes, seconds, miliseconds, + or -, timezoneoffset in hours and minutes 



    include('google-api-php-client/src/Google_Client.php'); 
    include('google-api-php-client/src/contrib/Google_CalendarService.php'); 

    session_start(); 

    $client = new Google_Client(); 
    $client->setApplicationName('doesntmatter-whateveryouwant'); 
    $client->setClientId('yourclientid'); 
    $client->setClientSecret('yourclientsecret'); 
    $client->setRedirectUri('yourredirecturl-setingoogleconsole'); 
    $client->setDeveloperKey('yourdeveloperkey'); 
    $cal = new Google_CalendarService($client); 

    if (isset($_GET['code'])) { 
     $client->authenticate($_GET['code']); 
     $_SESSION['token'] = $client->getAccessToken(); 
     header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 
    } 

    if (isset($_SESSION['token'])) { 
     $client->setAccessToken($_SESSION['token']); 
    } 

    if ($client->getAccessToken()) { 
     $event = new Google_Event(); 
    $event->setSummary($jobname); 
    $event->setDescription($jobdescription); 
    $event->setLocation($joblocation); 
    $start = new Google_EventDateTime(); 
    $start->setDateTime($startofjob); 
    $event->setStart($start); 
    $end = new Google_EventDateTime(); 
    $end->setDateTime($endofjob); 
    $event->setEnd($end); 

    $createdEvent = $cal->events->insert('[email protected]', $event); 
    echo $createdEvent->id; 


    $_SESSION['token'] = $client->getAccessToken(); 
    } else { 
     $authUrl = $client->createAuthUrl(); 
     print "<a class='login' href='$authUrl'>Connect Me!</a>"; 
    } 
?> 
相关问题