2

イベント ID で Google カレンダーから単一のCalendarEventEntryを取得しようとしていますが、その方法が見つかりません。API はこのためのメソッドを提供していないようですが、Queryを使用してフィード カレンダーへのクエリを作成することをお勧めします。これの欠点は、ID が考慮されるパラメーターの 1 つでないことです。

これを達成するための可能な方法は、カレンダーに関連付けられたCalendarEventFeedを取得し、次のように結果のイベント リストを反復処理することだと思います。

CalendarService service = new CalendarService(applicationName);
service.setUserCredentials(userName,password);
CalendarEventFeed myFeed = service.getFeed(feedUrl, CalendarEventFeed.class);
List <CalendarEventEntry> entries =  myFeed.getEntries();

for (CalendarEventEntry e : entries){
    if (e.getId().equals(id)){
       return e;
    }
    }

これを達成するためのより簡単で直接的な解決策を知っていますか??

前もって感謝します!

4

2 に答える 2

1

を呼び出すと、イベントの URL を取得できますcalendarEventEntry.getEditLink().getHref()。実際には、カレンダーの URL にイベント ID を加えたものです。

コード サンプルについては、Data API 開発者ガイドをご覧ください。

于 2010-01-26T12:00:06.580 に答える
0

みんなの質問には根拠があります。この質問に答えるコードはありませんでした。この質問に答えるために使用したコードの下を見つけてください。あなたのコードを少し修正しました

import com.google.gdata.client.*;
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.*;
import com.google.gdata.data.acl.*;
import com.google.gdata.data.calendar.*;
import com.google.gdata.data.extensions.*;
import com.google.gdata.util.*;

import java.net.*;
import java.io.*;
import java.util.List;


public class GetGoogleCalendarEventByID {

public static void main(String[] args) {

    System.out.println("Before Creating CalendarService.");
    CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0");
    System.out.println("After Creating CalendarService.");


    try
    {        
        System.out.println("Going to setUserCredentials.");
        myService.setUserCredentials("email@gmail.com", "password");        

        URL feedUrl =
          new URL("https://www.google.com/calendar/feeds/email@gmail.com/private/full");




        CalendarEventFeed myFeed = myService.getFeed(feedUrl, CalendarEventFeed.class);
        List <CalendarEventEntry> entries =  myFeed.getEntries();

        for (CalendarEventEntry e : entries){
            if (e.getId().equalsIgnoreCase("http://www.google.com/calendar/feeds/email%40gmail.com/events/EventIDLastPart")){
               System.out.println("Got the CalendarEventEntry: " + e.getId());
               System.out.println("CalendarEventEntry has text: " + e.getPlainTextContent());
            }
            }              


        System.out.println("Finished getting Event.");        




    }
    catch(Exception e)
    {
      System.out.println("Error : " + e.toString());

    }




}
}

注: feedUrl - これは、カレンダー設定の下にあるカレンダーの URL です。

イベント ID の形式はhttp://www.google.com/calendar/feeds/email%40gmail.com/events/EventIDLastPartです。

例えば

http://www.google.com/calendar/feeds/email%40gmail.com/events/ghytrueueyyrgfuur

それが役に立てば幸い

ンゴニダン

于 2013-12-19T12:50:31.020 に答える