2013-01-07 36 views
5

こんにちは、のイベントを作成しようとしています。 GoogleカレンダーAPIをアンドロイドで使用しています。アンドロイドを使用してカレンダーAPIを使用してGoogleカレンダーに予定を追加する方法は?

Googleで提供されているサンプルプロジェクトを作成しました。それぞれの手順に従って、プロジェクトを正常にコンパイルしました。

Googleカレンダーのこの例では、Googleカレンダーアカウントにのみカレンダー名を作成できますが、私はイベントを作成できません。

Googleカレンダーで予定を作成する方法はありますか?もしそうなら、私はどのようにそれを行うことができますか?

答えて

2

いくつかの時間を検索した後、私は最終的にちょうどそれがGoogleカレンダーAPIを使用してイベントを作成する方法を示しthis link

を通過.theの答えはグーグルドキュメント、それを自己にあった解決策を見つけるしています。

+0

私はコードを送ることができますか、Googleカレンダーにイベントを追加する方法を教えてくださいまたはbackground.iのアプリは、私のカスタムカレンダーから1つの日付を選択している間にイベントを追加したいと思います。そして、私はログインカレンダーのGoogleカレンダーでそのデフォルトのevnetを見ることができます – Google

+1

hiiiはどのようにGoogleカレンダーポップアップを開くことなく、私はdocを理解できません。私はAPIを作って、Googleアカウントでキーを追加しました。しかし、イベントを追加する方法を理解できませんplz私に教えてください? – Google

+0

質問のソースコードをダウンロードするだけでコード – Ramz

2

これはお尻のような巨大な痛みですが、私は最終的に少なくともイベントを作成するために働いています。

最新のGoogle PHP APIジップをダウンロードして、ウェブサーバーのインクルードフォルダにアップロードします。 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('[email protected]', $event); 
    echo $createdEvent->id; 


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