简体   繁体   English

如何使用Android使用日历API在谷歌日历上添加事件?

[英]How to add event on google calendar using calendar API using android?

Hi I am trying to create an event in Google calendar using Google calendar API in android. 嗨,我正在尝试使用Android中的Google日历API在Google日历中创建一个事件。

I have created a sample project provided by Google , and I followed the each steps and compiled the project successfully. 我创建了一个由Google提供的示例项目,我按照每个步骤成功编译了项目。

But in this Example of Google calendar, I can only create a calendar name to my Google calendar account, I can't create any event. 但在这个Google日历示例中,我只能为我的Google日历帐户创建日历名称,我无法创建任何活动。

Is there any way to create an event in Google calendar? 有没有办法在Google日历中创建活动? If so how can I do it? 如果是这样我该怎么办?

After Searching for some time i have finally find the solution .the answer was in the google document it self just go through this link 搜索了一段时间后,我终于找到了解决方案。答案是在google文档中,它自己只是通过这个链接

it shows how to create an event using google calender api. 它显示了如何使用谷歌日历api创建一个事件。

This is such a giant pain in the ass - but I finally got it working for creating events at least. 这是一个巨大的痛苦 - 但我终于让它至少为创造事件而努力。

Download the most recent Google PHP API zip, and upload it to your includes folder on your webserver. 下载最新的Google PHP API压缩文件,并将其上传到您的网络服务器上的包含文件夹。 Use Google API Console to set up an API client. 使用Google API控制台设置API客户端。 Make sure you set your redirect url to be the same as your page's url - so it redirects to its self. 确保将重定向网址设置为与网页网址相同 - 因此重定向到自己的网址。

I've initially just set some variables for event details, you can make a form which shoves these in if you want. 我最初只为事件详细信息设置了一些变量,如果你愿意,你可以制作一个推送这些变量的表格。

Here's my code: 这是我的代码:

<?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('YOURCALENDARID@GOOGLE.COM', $event);
    echo $createdEvent->id;


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Android 上使用 API 将事件添加到 Google 日历 - How to add an event to Google Calendar using the API on Android 如何使用Google Calendar API在Android中获取Google Calendar事件? - How to get Google Calendar events in android using google calendar api? Google Calendar API:在Android中以编程方式将经度添加到Calendar Event吗? - Google Calendar API: add latitude longitude to Calendar Event programmatically in android? 适用于Android的Google Calendar API-如何为活动添加访客身份? - Google Calendar API for Android - How to Add Rooms as Guests for an Event? 如何在 Android Studio 中向 Google Calendar API 添加事件? - How can I add an event to the Google Calendar API in Android Studio? 如何在Android中将事件添加到Google日历? - How to add event to Google calendar in android? Android:可以在不调用Google Calendar API或启动原生日历活动的情况下添加日历活动吗? - Android : Is possible to add calendar event without calling the Google Calendar API or Starting Native Calendar activity? 如何使用Intent添加日历事件? - How to add a calendar event using Intents? Android使用事件ID和日历中的手动视图添加事件 - Android add event using event id with manual view in Calendar Android:Google Calendar API:如何执行create event方法? - Android: Google Calendar API: how to execute create event method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM