我正在创建我的应用程序,我想将其与Google帐户集成,我遇到以下问题:
我想授权用户并返回此页面,然后从谷歌日历中分享一些数据。 所以这是我创建登录URL(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 :(得分: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>