无法在Android应用中集成Google Calendar API

时间:2011-01-23 13:51:25

标签: android google-calendar-api

我已经尝试了几天将Google日历集成到我的Android应用中,但收效甚微。我已经实现了GData API,并使用了他们为测试目的而提供的代码,但是仍然收到SAXParser错误,如下所示。我需要做的就是在用户的日历中创建新事件。

01-23 19:10:40.420: WARN/XmlParser(28605): javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
01-23 19:10:40.420: WARN/XmlParser(28605): javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
01-23 19:10:40.420: WARN/XmlParser(28605):     at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:84)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:682)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:576)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.data.BaseEntry.parseAtom(BaseEntry.java:1015)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:59)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:39)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.wireformats.input.CharacterParser.parse(CharacterParser.java:100)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.wireformats.input.XmlInputParser.parse(XmlInputParser.java:52)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:66)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:34)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.client.Service.parseResponseData(Service.java:2165)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.client.Service.insert(Service.java:1410)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.google.gdata.client.GoogleService.insert(GoogleService.java:606)
01-23 19:10:40.420: WARN/XmlParser(28605):     at <packagename>.CalendarDialog.addToCalendar(CalendarDialog.java:160)
01-23 19:10:40.420: WARN/XmlParser(28605):     at <packagename>.CalendarDialog.onClick(CalendarDialog.java:125)
01-23 19:10:40.420: WARN/XmlParser(28605):     at android.view.View.performClick(View.java:2421)
01-23 19:10:40.420: WARN/XmlParser(28605):     at android.view.View$PerformClick.run(View.java:8869)
01-23 19:10:40.420: WARN/XmlParser(28605):     at android.os.Handler.handleCallback(Handler.java:587)
01-23 19:10:40.420: WARN/XmlParser(28605):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 19:10:40.420: WARN/XmlParser(28605):     at android.os.Looper.loop(Looper.java:143)
01-23 19:10:40.420: WARN/XmlParser(28605):     at android.app.ActivityThread.main(ActivityThread.java:5097)
01-23 19:10:40.420: WARN/XmlParser(28605):     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 19:10:40.420: WARN/XmlParser(28605):     at java.lang.reflect.Method.invoke(Method.java:521)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-23 19:10:40.420: WARN/XmlParser(28605):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-23 19:10:40.420: WARN/XmlParser(28605):     at dalvik.system.NativeStart.main(Native Method)
01-23 19:10:40.420: WARN/System.err(28605): com.google.gdata.util.ParseException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:708)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:576)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.data.BaseEntry.parseAtom(BaseEntry.java:1015)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:59)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:39)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.wireformats.input.CharacterParser.parse(CharacterParser.java:100)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.wireformats.input.XmlInputParser.parse(XmlInputParser.java:52)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:66)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:34)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.client.Service.parseResponseData(Service.java:2165)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.client.Service.insert(Service.java:1410)
01-23 19:10:40.420: WARN/System.err(28605):     at com.google.gdata.client.GoogleService.insert(GoogleService.java:606)
01-23 19:10:40.430: WARN/System.err(28605):     at <packagename>.CalendarDialog.addToCalendar(CalendarDialog.java:160)
01-23 19:10:40.430: WARN/System.err(28605):     at <packagename>.CalendarDialog.onClick(CalendarDialog.java:125)
01-23 19:10:40.430: WARN/System.err(28605):     at android.view.View.performClick(View.java:2421)
01-23 19:10:40.430: WARN/System.err(28605):     at android.view.View$PerformClick.run(View.java:8869)
01-23 19:10:40.430: WARN/System.err(28605):     at android.os.Handler.handleCallback(Handler.java:587)
01-23 19:10:40.430: WARN/System.err(28605):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-23 19:10:40.430: INFO/dalvikvm(28605): Jit: resizing JitTable from 4096 to 8192
01-23 19:10:40.440: WARN/System.err(28605):     at android.os.Looper.loop(Looper.java:143)
01-23 19:10:40.440: WARN/System.err(28605):     at android.app.ActivityThread.main(ActivityThread.java:5097)
01-23 19:10:40.440: WARN/System.err(28605):     at java.lang.reflect.Method.invokeNative(Native Method)
01-23 19:10:40.440: WARN/System.err(28605):     at java.lang.reflect.Method.invoke(Method.java:521)
01-23 19:10:40.440: WARN/System.err(28605):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-23 19:10:40.440: WARN/System.err(28605):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-23 19:10:40.440: WARN/System.err(28605):     at dalvik.system.NativeStart.main(Native Method)
01-23 19:10:40.440: WARN/System.err(28605): Caused by: javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
01-23 19:10:40.450: WARN/System.err(28605):     at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:84)
01-23 19:10:40.450: WARN/System.err(28605):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:682)
01-23 19:10:40.450: WARN/System.err(28605):     ... 25 more

我用于添加事件的代码是:

void addToCalendar() throws IOException, ServiceException
    {
        CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
        myService.setUserCredentials("<username>@gmail.com", "<password>");

    URL postUrl =
          new URL("https://www.google.com/calendar/feeds/<username>@gmail.com/private/full");
        CalendarEventEntry myEntry = new CalendarEventEntry();

        myEntry.setTitle(new PlainTextConstruct("Tennis with Beth"));
        myEntry.setContent(new PlainTextConstruct("Meet for a quick lesson."));

        DateTime startTime = DateTime.parseDateTime("2011-01-26T15:00:00+05:30");
        DateTime endTime = DateTime.parseDateTime("2011-01-26T15:12:00+05:30");
        When eventTimes = new When();
        eventTimes.setStartTime(startTime);
        eventTimes.setEndTime(endTime);
        myEntry.addTime(eventTimes);

        // Send the request and receive the response:
        CalendarEventEntry insertedEntry = myService.insert(postUrl, myEntry);
}

知道是什么导致了这个问题吗?此外,如果有人运行了Calendar API,他们可以提供一些帮助吗?就像我说的,我所需要的只是添加事件(单个和重复)

谢谢!

3 个答案:

答案 0 :(得分:2)

GData API无法在您的Android上运行,请使用google api客户端,而不是http://code.google.com/p/google-api-java-client/wiki/Android

请参阅:Best option for using the GData APIs on Android?

答案 1 :(得分:0)

答案 2 :(得分:0)

您可以使用GoogleApiJavaClient吗? 看到这里原因: http://code.google.com/p/gdata-java-client/wiki/MigratingToGoogleApiJavaClient

在这里寻找更多资源 http://code.google.com/p/google-api-java-client/