誰も答えなかったので、Google Calendar API の PHP 以外のドキュメント、特に .NET に関するドキュメントと生のプロトコルを少しだけ調べてみることにしました。そして、あなたはそれを知らないでしょうか...
.NET のドキュメントにアクセスすると、優れた新機能、特に、認証されたユーザー用に新しい非プライマリ カレンダーを作成する方法と、非プライマリ カレンダーにイベントを追加する方法について言及されています。
もちろん、このドキュメントは PHP 領域のどこにも表示されず、1 対 1 の相関関係はないようです。新しいカレンダーを作成するために、最初にいくつかの明白なことを試してから、壊れたものを探して、それほど明白ではないことを試しました。ラジオの沈黙の理由が、誰も答えを知らなかったが、確かに知りたいということだった場合に備えて、共有したいと思いました.
新しいカレンダーを作成するには:
これには 2 つの鍵があります。
カレンダー イベントを追加するには、同じ方法を使用する必要があります。insertEvent()
メソッドで投稿 URL を設定する必要があります。それ以外の場合は、デフォルトのフィード URL に移動します。
この例では、App Calendar が既に存在するかどうかを確認し、存在しない場合は作成します。
//Standard creation of the HTTP client
$gdataCal = new Zend_Gdata_Calendar($client);
//Get list of existing calendars
$calFeed = $gdataCal->getCalendarListFeed();
//Set this to true by default, only gets set to false if calendar is found
$noAppCal = true;
//Loop through calendars and check name which is ->title->text
foreach ($calFeed as $calendar) {
if($calendar -> title -> text == "App Calendar") {
$noAppCal = false;
}
}
//If name not found, create the calendar
if($noAppCal) {
// I actually had to guess this method based on Google API's "magic" factory
$appCal = $gdataCal -> newListEntry();
// I only set the title, other options like color are available.
$appCal -> title = $gdataCal-> newTitle("App Calendar");
//This is the right URL to post to for new calendars...
//Notice that the user's info is nowhere in there
$own_cal = "http://www.google.com/calendar/feeds/default/owncalendars/full";
//And here's the payoff.
//Use the insertEvent method, set the second optional var to the right URL
$gdataCal->insertEvent($appCal, $own_cal);
}
そして、あなたはそれを持っています。次の目標は、既定のカレンダーではなく、そのカレンダーにイベントを挿入することです。
非プライマリ カレンダーへのイベントの追加
おそらく推測できる簡単な部分は、そのオプションの URL を :insertEvent($newEvent, $calURL)
のように再度設定する必要があることです。トリッキーな部分は、カレンダーの URL を取得することです。「所有されたカレンダー」パスとは異なり、特定のカレンダーにはユーザー固有の情報が含まれているだけでなく、ある種のハッシュルックイン ID も含まれています。
コードは次のとおりです。
//Set up that loop again to find the new calendar:
$calFeed = $gdataCal->getCalendarListFeed();
foreach ($calFeed as $calendar) {
if($calendar->title->text == "App Calendar")
//This is the money, you need to use '->content-src'
//Anything else and you have to manipulate it to get it right.
$appCalUrl = $calendar->content->src;
}
//.......... Some Assumed MySQL query and results .............
while ($event = $result->fetch_assoc()) {
$title = $event['description'];
//Quick heads up
//This is a handy way of getting the date/time in one expression.
$eventStart = date('Y-m-d\TH:i:sP', strtotime($event['start']));
$eventEnd = date('Y-m-d\TH:i:sP', strtotime($event['end']));
$newEvent = $gdataCal->newEventEntry();
$newEvent->title = $gdataCal->newTitle($title);
$when = $gdataCal->newWhen();
$when->startTime = $eventStart;
$when->endTime = $eventEnd;
$newEvent->when = array($when);
//And at last, the insert is set to the calendar URL found above
$createdEvent = $gdataCal->insertEvent($newEvent, $appCalUrl);
}
echo "<p>".$result->num_rows." added to your Google calendar.</p>";
私の質問を読んで、それについて考えてくれた人に感謝します。誰かが上記のコードを引き締める方法を知っている場合 (おそらく 2 つのループは必要ありませんか?)、フィードバックをお待ちしております。