2010-05-08 79 views
2

我正在用GWT编写应用程序,并且在互联网上发现有一个库可以轻松使用gdata功能。特别是我需要使用与Google日历的集成。我遵循gwt-gdata网站上的官方指南进行身份验证(http://code.google.com/p/gwt-gdata/wiki/GettingStarted),但不幸的是,我收到了一个错误消息。这是错误:Gwt-gdata身份验证

17:59:12.463 [ERROR] [testmappa] Unable to load module entry point class testMappa.client.TestMappa (see associated exception for details) 
    com.google.gwt.core.client.JavaScriptException: 
(TypeError): $wnd.google.accounts is undefined 
    fileName: http://127.0.0.1:8888 
    lineNumber: 29 
    stack: ("http://www.google.com/calendar/feeds/")@http://127.0.0.1:8888:29 
    connect("http://127.0.0.1:8888/TestMappa.html?gwt.codesvr=127.0.0.1:9997","`gL1<a3s4B&Y{(Ci","127.0.0.1:9997","testmappa","2.0")@:0 
    ((void 0),"testmappa","http://127.0.0.1:8888/testmappa/")@http://127.0.0.1:8888/testmappa/hosted.html?testmappa:264 
    z()@http://127.0.0.1:8888/testmappa/testmappa.nocache.js:2 
    (-2)@http://127.0.0.1:8888/testmappa/testmappa.nocache.js:8 
     at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195) 
     at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120) 
     at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507) 
     at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264) 
     at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 
     at com.google.gwt.accounts.client.User.login(User.java) 
     at testMappa.client.TestMappa.onModuleLoad(TestMappa.java:68) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:369) 
     at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:185) 
     at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:380) 
     at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222) 
     at java.lang.Thread.run(Thread.java:637) 

我无法理解此错误的原因。我的代码很简单:

String scope = "http://www.google.com/calendar/feeds/"; 

    User.login(scope); 

而据我所知,它应该可以正常工作。我不知道该怎么做,我在这里问如何解决这个问题,如果我可以直接使用gdata本地java库,但我相信这个其他的东西是不可能做到的客户端gwt代码(因为代码将被转换为JavaScript)。

谢谢。

回答

2

你上面贴的两行代码实际上应该来的run方法中这样的 -

 
if (GData.isLoaded(GDataSystemPackage.CALENDAR)) { 
    Window.alert("Package is loaded"); 
} else { 
    GData.loadGDataApi("MyApiKey", 
     new Runnable() { 
     public void run() { 
      String scope = "http://www.google.com/calendar/feeds/"; 
      User.login(scope); 
      //remaining code comes in here. you may create a new method 
      //and call it from here. 
     } 
     }, 
     GDataSystemPackage.CALENDAR); 
} 

如果不加载的GData API代码,你很可能得到的JavaScript错误,你粘贴。

+0

这似乎工作,但我不明白,我写了上面的两行代码后粘贴在这里的代码,并没有工作...顺便说一句,谢谢! – Raffo 2010-05-09 09:32:49

+0

您需要了解javascript的异步性质。阅读此主题帖子 - http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/faca1575f306ba0f – 2010-05-09 09:40:37