开发者

How to get a single GoogleCalendar CalendarEventEntry by its ID?

I'm trying to retrieve a single CalendarEventEntry from a Google Calendar by the event ID but I can't find the way to do it. It seems that the API doesn't provide a method 开发者_JAVA百科for this, though it suggests to make a query to the feed calendar using Query. The drawback of this is that the ID is not one of the parameters considered.

I think that a possible way to achieve this would be to get the CalendarEventFeed associated with our calendar and then iterate over the resulting list of events as follows:

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;
    }
    }

Do you know any easier and more straight solution to achieve this ??

Thanks in advance!


You can get the URL of the event by calling calendarEventEntry.getEditLink().getHref(). It is actually the url of the calendar plus the event id.

Take a look at the Data API Developer Guide for code samples.


The guys question has basis, there was no code to answer this question. Find below the code i used to answer this question. I modified your code slightly

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());

    }




}
}

NOTE: feedUrl - That is the Calendar URL you find under the calendar settings

An event id has the format http://www.google.com/calendar/feeds/email%40gmail.com/events/EventIDLastPart

e.g.

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

Hope it helps

Ngonidan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜