GoogleTokenResponse没有执行..!

时间:2016-02-10 09:53:40

标签: java android oauth-2.0 google-api google-oauth

我正在尝试创建一个应用程序,该应用程序可以在没有安装Play服务的设备上运行。目前我正在登录,使用webview。我已在此处成功收到授权码,&要检索访问令牌,我正在使用以下代码段(来自https://developers.google.com/api-client-library/java/google-api-java-client/reference/1.20.0/com/google/api/client/googleapis/auth/oauth2/GoogleAuthorizationCodeTokenRequest

不知何故,在GoogleTokenResponse上,appplication在.execute()崩溃了...我应该在这里改变什么?

@Override
            public void onPageFinished(android.webkit.WebView view, String url) {
                super.onPageFinished(view, url);
                if (url.startsWith(OAuth2Client.REDIRECT_URI)) {
                    try {
                        if (url.indexOf("code=") != -1) {
                            String code = extractCodeFromUrl(url);

                            try {
                                GoogleTokenResponse response =
                                        new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(),
                                                OAuth2Client.CLIENT_ID, OAuth2Client.CLIENT_SECRET,
                                                code, OAuth2Client.REDIRECT_URI)
                                                .execute();                                                                  //debugging stops here!!
                                System.out.println("Access token: " + response.getAccessToken());
                            } catch (TokenResponseException e) {
                                if (e.getDetails() != null) {
                                    System.err.println("Error: " + e.getDetails().getError());
                                    if (e.getDetails().getErrorDescription() != null) {
                                        System.err.println(e.getDetails().getErrorDescription());
                                    }
                                    if (e.getDetails().getErrorUri() != null) {
                                        System.err.println(e.getDetails().getErrorUri());
                                    }
                                } else {
                                    System.err.println(e.getMessage());
                                }
                            }


                        } else if (url.indexOf("error=") != -1) {
                            OAuth2Client.ClearAccessToken(getApplicationContext());
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("onPageFinished : " + url);
            }

0 个答案:

没有答案