[英]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.