2014-06-22 37 views
0

我已成功使用Google Calendar API的Java .jar文件创建日历条目。尽管我有以下所示的日历,但他们总是会进入“步枪”日历。我需要知道如何指定条目所属的日历。例如,我将在何处指定“会议”或“散弹枪”使用Java API创建日历条目时选择特定的日历

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

Google Calendar possibilities

public void create() { 
     try { 
      CalendarService myService = new CalendarService("My Service"); 
      myService.setUserCredentials("mycalendar", "mypassword"); 

      URL postUrl = new URL("http://www.google.com/calendar/feeds/[email protected]/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("[email protected]"); 
      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(); 
     } 
+0

它帮助,如果你发布你使用的是创建日历条目的代码,所以我们可以找出什么在改变它。对于一般示例,您需要转到[Google文档(已链接)](https://developers.google.com/google-apps/calendar/v2/developers_guide_java#CreatingEvents) –

回答

0

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

public void retrieve() { 
     try { 
      CalendarService myService = new CalendarService("QuanticoShootingclub"); 
      myService.setUserCredentials("[email protected]", "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(); 
     } 
    } 

您也可以通过转到您的Google日历在网络上执行此操作。点击下拉菜单,然后选择日历设置>日历地址:(日历ID:@ group.calendar.google.com)

然后,在创建新日历条目时,将此ID替换为主ID 。

注意:从原代码

  URL postUrl = new URL("http://www.google.com/calendar/feeds/***<secondary calendar ID>***/private/full");