2011-03-25 94 views

回答

3
UserService userService = UserServiceFactory.getUserService(); 
User user = userService.getCurrentUser(); 

if (user != null) { 
    String email = user.getEmail(); 
} else { 
    // no user logged in 
} 

而且看看文檔:http://code.google.com/appengine/docs/java/gettingstarted/usingusers.html

更新:

當然,你需要啓用用戶authenticaiton在配置中要求用戶登錄並看到自己的數據:http://code.google.com/appengine/docs/java/config/webxml.html#Security_and_Authentication

查看此處查看如何自行登錄: http://code.google.com/appengine/docs/java/users/overview.html

+0

只返回null,我需要重定向用戶登錄他的谷歌帳戶,並重新導向到我的應用程序,我有一個URL,但只返回一個令牌,我真的不知道,並且無法找到如何使用它, http://www.google.com/a/sanmina-sci.com/AuthSubRequest?scope=http://www.google.com/m8/feeds/&session=1&secure=0&next=http://www.example。 com/welcome.html – Charlires 2011-03-29 15:18:49

+0

您必須配置您的應用程序以要求認證 - 請參閱更新的答案。 – 2011-03-31 08:58:23