繁体   English   中英

使用Android和App Engine(GAE)登录Google

[英]Login Google with Android and App Engine (GAE)

我有一个关于Google App Engine的项目和一个Android项目。 我需要使用Android在GAE上登录。

在GAE上,我有以下代码:(将用户重定向到Google登录页面,这正是我想要的!)

    UserService userService = UserServiceFactory.getUserService();        
    String URL = request.getRequestURI();

    if (request.getUserPrincipal() != null) {
        // I need to send the MY_GENERATED_TOKEN to my android app
        response.getWriter().println(MY_GENERATED_TOKEN);
    } else {
        response.sendRedirect(userService.createLoginURL(URL));
    }

此代码是默认代码,由Google建议。 我的问题是我不知道如何在我的Android应用程序上访问它。

我有一个带有按钮的Android活动。 我希望当我单击按钮时,在Google的登录页面上打开android浏览器,然后登录,浏览器会自动关闭,我的应用会收到GAE生成的令牌(这不是Google令牌,它是由Google生成的令牌我)。

我不想使用端点。

如果您真的想使用默认浏览器打开它,这是我的方法:

1. Open Login Page url
2. Login then redirect to an android handled intent-filter from your app
    # example: http://your-caught-login-intent-filter.example.com or
    # your-app-login://scheme
3. Pass along the token and you're set

但是我建议只使用webview,这样您将拥有更多控制权:

1. Create a webview, then load the login url
2. Make sure to set the webviewClient onFinishPage
3. Lookup the resulting html for your token

http://developer.android.com/reference/android/webkit/WebView.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM