如何通过 ID 获取单个 GoogleCalendar CalendarEventEntry?

发布于 2024-08-19 01:13:42 字数 1046 浏览 11 评论 0原文

我正在尝试检索单个 CalendarEventEntry 来自 Google 日历的事件 ID,但我找不到执行此操作的方法。该 API 似乎没有为此提供方法,但它建议使用 查询。这样做的缺点是 ID 不是考虑的参数之一。

我认为实现此目的的一种可能方法是获取 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;
    }
    }

您知道有任何更简单、更直接的解决方案来实现此目的吗?

提前致谢!

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 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£烟消云散 2024-08-26 01:13:42

您可以通过调用calendarEventEntry.getEditLink().getHref()获取事件的URL。它实际上是日历的 url 加上事件 id。

请参阅数据 API 开发人员指南代码示例。

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.

无远思近则忧 2024-08-26 01:13:42

这家伙的问题有根据,没有代码来回答这个问题。下面找到我用来回答这个问题的代码。我稍微修改了您的代码

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 protected]", "password");        

        URL feedUrl =
          new URL("https://www.google.com/calendar/feeds/[email protected]/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/ghytrueueyryrgfuur

希望对

恩戈尼丹有帮助

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 protected]", "password");        

        URL feedUrl =
          new URL("https://www.google.com/calendar/feeds/[email protected]/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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文