首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Java API创建日历条目时选择特定日历

使用Java API创建日历条目时选择特定日历
EN

Stack Overflow用户
提问于 2014-06-22 11:33:38
回答 1查看 139关注 0票数 0

我已经成功地使用Java .jar文件为Google calendar API创建了日历条目。他们总是进入“步枪”日历,即使我有下面显示的日历。我需要知道如何指定条目所属的日历。例如,我应该在哪里指定“会议”或“猎枪”?

我没有看到如何指定特定日历的任何东西或任何示例。

代码语言:javascript
复制
    public void create() {
        try {
            CalendarService myService = new CalendarService("My Service");
            myService.setUserCredentials("mycalendar", "mypassword");

            URL postUrl = new URL("http://www.google.com/calendar/feeds/myurl@junk.com/private/full");

            CalendarEventEntry myEntry = new CalendarEventEntry();
        //myEntry.setIcalUID("Rec Fire");

            DateTime startTime = DateTime.parseDateTime("2014-06-22T09:00:00");
            DateTime endTime = DateTime.parseDateTime("2014-06-22T13:00:00");

                When eventTimes = new When();
            eventTimes.setStartTime(startTime);
            eventTimes.setEndTime(endTime);
            myEntry.addTime(eventTimes);
            Where eventLocation = new Where();
            eventLocation.setLabel("R-4");
            eventLocation.setValueString("value string");
            eventLocation.setRel("REL");
            myEntry.addLocation(eventLocation);
            EventWho eventWho = new EventWho();
        eventWho.setAttendeeStatus("attendee status");
            eventWho.setAttendeeType("Meetings");
            eventWho.setValueString("who value string");
            eventWho.setEmail("myemailt@email.com");
            eventWho.setRel("who rel");
        myEntry.addParticipant(eventWho);
            myEntry.setTitle(new PlainTextConstruct("R-4 Rifles Only"));
            myEntry.setContent(new PlainTextConstruct("Paragraph HURST MULLINS"));


            CalendarEventEntry insertedEntry = myService.insert(postUrl,  myEntry);
        } catch (Exception e) {
            e.printStackTrace();
        }
EN

回答 1

Stack Overflow用户

发布于 2014-06-23 02:04:39

我想通了。首先,您必须获取您的辅助日历的ID

代码语言:javascript
复制
    public void retrieve() {
        try {
            CalendarService myService = new CalendarService("QuanticoShootingclub");
            myService.setUserCredentials("calendar@quanticoshootingclub.com", "washington13");

            URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/owncalendars/full");
            CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class);

            System.out.println("Your calendars:");
            System.out.println();

            for (int i = 0; i < resultFeed.getEntries().size(); i++) {
                CalendarEntry entry = resultFeed.getEntries().get(i);
                System.out.println("\t" + entry.getTitle().getPlainText());
                System.out.println("\t\t" + entry.getId());
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

你也可以通过在网络上登录到你的谷歌日历来做到这一点。单击下拉菜单,然后单击日历设置>日历地址:(日历ID:@group.calendar.google.com)

然后,当您创建新的日历条目时,您可以用这个ID替换主ID。

注意:来自原始代码

代码语言:javascript
复制
           URL postUrl = new URL("http://www.google.com/calendar/feeds/***<secondary calendar ID>***/private/full");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24347897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档