3

好吧,我放弃了。任何人都有使用 Google 的 IssueAuthToken 和 MergeSession 对某些没有官方 API 访问权限的 Google 服务进行身份验证的经验吗?在这种情况下,我正在尝试获取 Google 书签(来自 google.com/bookmarks)。

我使用 getAuthToken 获取 SID 和 LSID,效果很好。然后我打电话

Uri ISSUE_AUTH_TOKEN_URL = Uri.parse("https://accounts.google.com/IssueAuthToken?service=bookmarks&Session=false");

String url = ISSUE_AUTH_TOKEN_URL.buildUpon()
                 .appendQueryParameter("SID", sid)
                 .appendQueryParameter("LSID", lsid)
                 .build().toString();

我收到“ubertoken”。

然后我对 MergeSession 进行 GET 操作,这就是一切都出错的地方:

String url2 = "https://accounts.google.com/MergeSession?source=chrome&uberauth="+uberToken+"&service=bookmarks&continue=https%3A%2F%2Fwww.google.com%2Fbookmarks%2F";
HttpGet getCookies = new HttpGet(url2);

查看 getCookies 的标题,我没有看到我应该看到的额外 cookie,而且我还看到了类似X-Frame-Options: DENY.

请帮忙)!

4

1 回答 1

0

Okay friends, here we go. It seems the above is now unreliable/broken at least occasionally as of August 2013. This is how I'm doing it now and it seems to work. It tries the above first, and if it fails, goes on to method #2.

  final Account acct = am.getAccountsByType("com.google")[acctid];
  final String tokenType = "weblogin:service=bookmarks&continue=https://www.google.com/bookmarks/";

    am.getAuthToken(acct, tokenType, null, this, new AccountManagerCallback<Bundle>() {
        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            try {
                final String accessToken = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
                if (accessToken.contains("WILL_NOT_SIGN_IN")) {
                    am.getAuthToken(acct, "SID", null, MainActivity.this, new AccountManagerCallback<Bundle>() {
                        @Override
                        public void run(AccountManagerFuture<Bundle> future) {
                            try {
                                sid = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
                            } catch (OperationCanceledException e) {
                                finish();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }

                            am.getAuthToken(acct, "LSID", null, MainActivity.this, new AccountManagerCallback<Bundle>() {
                                @Override
                                public void run(AccountManagerFuture<Bundle> future) {
                                    try {
                                        lsid = future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
                                    } catch (OperationCanceledException e) {
                                        finish();
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                    Thread t = new Thread() {
                                        public void run() {
                                            try {
                                                Uri ISSUE_AUTH_TOKEN_URL = Uri.parse("https://www.google.com/accounts/IssueAuthToken?service=gaia&Session=false");
                                                Uri TOKEN_AUTH_URL = Uri.parse("https://www.google.com/accounts/TokenAuth");

                                                final HttpClient httpclient = new DefaultHttpClient();
                                                httpclient.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
                                                httpclient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);

                                                String url = ISSUE_AUTH_TOKEN_URL.buildUpon().appendQueryParameter("SID", sid).appendQueryParameter("LSID", lsid).build().toString();
                                                HttpPost getUberToken = new HttpPost(url);
                                                HttpResponse response = httpclient.execute(getUberToken);

                                                String uberToken = EntityUtils.toString(response.getEntity(), "UTF-8");

                                                final String accessToken2 = TOKEN_AUTH_URL.buildUpon()
                                                        .appendQueryParameter("source", "android-browser")
                                                        .appendQueryParameter("auth", uberToken)
                                                        .appendQueryParameter("continue", "https://www.google.com/bookmarks/").build().toString();

                                                //do stuff
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    };
                                    t.start();
                                }
                            }, null);
                        }
                    }, null);
                } else {             
                    //do stuff
                }
            } catch (OperationCanceledException e) {
                finish();
            } catch (Exception e) {
                finish();                 
            }
        }
    }, null);   
于 2013-08-20T15:59:53.030 回答