10

こんにちは、Android で Google カレンダー API を使用して Googleカレンダーでイベントを作成しようとしています。

Googleが提供するサンプル プロジェクトを作成し 、各手順に従ってプロジェクトを正常にコンパイルしました。

しかし、この Google カレンダーの例では、自分の Google カレンダー アカウントにカレンダー名しか作成できず、イベントを作成できません。

Google カレンダーでイベントを作成する方法はありますか? もしそうなら、どうすればできますか?

4

2 に答える 2

7

しばらく検索した後、私は最終的に解決策を見つけました。答えはグーグルドキュメントにありましたそれ自体は このリンクを通過するだけです

googlecalenderapiを使用してイベントを作成する方法を示しています。

于 2013-01-17T06:51:10.790 に答える
5

これはお尻の大きな痛みですが、少なくともイベントを作成するためにようやく機能するようになりました。

最新の Google PHP API zip をダウンロードし、ウェブサーバーの includes フォルダーにアップロードします。Google API コンソールを使用して API クライアントをセットアップします。リダイレクト URL がページの URL と同じになるように設定してください。これにより、ページ自体にリダイレクトされます。

最初に、イベントの詳細にいくつかの変数を設定しました。必要に応じて、これらを押し込むフォームを作成できます。

これが私のコードです:

<?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>";
    }
?>
于 2013-12-20T15:52:00.673 に答える