我们为 Google Health 开发并发布了一款应用。现在我们希望通过询问用户名和密码来避免每次登录 gmail 帐户。为此,我听说我可以有以下选择。1. OAuth 2. 客户经理 3.
OAuth 的问题在于它将通过 Android -> Web App -> Health 路径,所以我还需要开发一个我们现在不希望这样做的 Web 应用程序。
所以我正在尝试使用帐户管理器,这是我的代码,我可以使用它获取帐户列表和所选帐户的有效 authToken。
AccountManager mgr = AccountManager.get(getApplicationContext());
System.out.println("Got account manager");
Account[] accts = mgr.getAccounts();
}
Account acct = accts[0];
AccountManagerFuture<Bundle> accountManagerFuture = mgr.getAuthToken(acct, "android", null, this, null, null);
Bundle authTokenBundle = accountManagerFuture.getResult();
System.out.println("Account name "+accts[0].name);
String authToken = authTokenBundle.get(AccountManager.KEY_AUTHTOKEN).toString();
System.out.println("Got token:"+authToken);
但是现在我对如何使用这个令牌来访问健康数据感到困惑。为了获取人口统计信息,我们使用了以下代码,我们明确地让用户登录到我们的应用程序。
String queryURL = "https://www.google.com/health/feeds/profile/ui/" + profileId +"/-/DEMOGRAPHICS";
getDemoGrInfoQuery = new Query(new URL(queryURL));
Feed dempGrResultFeed;
globals = new Globals();
dempGrResultFeed = healthService.query(getDemoGrInfoQuery, Feed.class);
因此,我们过去常常使用 URL 来获取 Feed。
现在我想跳过登录过程并使用上面的 authToken 来检索提要。如何才能做到这一点?
任何帮助将非常感激!!!提前致谢,