2010-08-23 33 views
0

我创建了我的申请,我想它与谷歌帐户集成,我有以下问题:问题的登录,userService,失去了会话 - 谷歌应用程序angine

我想对用户进行授权,并回到这个页面和共享谷歌日历的一些数据后。 所以这是我的代码片段创建登录网址(index.jsp)之后

boolean b= true; 
UserService userService = UserServiceFactory.getUserService(); 
    User user = userService.getCurrentUser(); 

if(user!=null){ 
%> 
       <p>Hello, <%= user.getNickname() %> </p> 
<% 
           } 

    try 
       {singleUseToken AuthSubUtil.getTokenFromReply(request.getQueryString()); 

       }catch (NullPointerException e) 
       { 

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

     String login=AuthSubUtil.getRequestUrl(nextUrl, scope, false, true); 

%> 
    <p>"App needs access to your Google Calendar account to read your Calendar feed. To authorize MyApp to access your account 
    <a href="<%=userService.createLoginURL(login) %>">log in to your account</a>.)</p> 
<% 
b=false; 
    } 

    if (b== true){ 

     CalendarService myService=null; 
       try{  
        sessionToken = AuthSubUtil.exchangeForSessionToken(URLDecoder.decode(singleUseToken, "UTF-8"), null); 
       } 
       catch(NullPointerException e) 
       { 

       %> 
         <p><%=e %> </p> 
<% 
        } 
CalendarService myService = new CalendarService("google-ExampleApp-v1.0"); 
        myService.setAuthSubToken(sessionToken); 
        ... 

我创建authSubUrl并将它传递一个到UserService创建第二个重定向,但UserService.getCurrentUser()虽然返回null我登录了。 第二个问题是会话丢失 - 当我转到其他.jsp页面时,我从我的账户注销。

请帮

回答

0

确保您已在应用程序的的AppEngine-web.xml中

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> 
    <application>myapp</application> 
    <version>01</version> 
    <ssl-enabled>true</ssl-enabled> 
    <sessions-enabled>true</sessions-enabled> <!- <<<< Make sure you have this -> 
</appengine-web-app> 
+0

我加入这个配置的启用会话 -属性,但它并没有帮助。也许index.jsp中的代码是错误的? – qazah 2010-08-23 13:20:33