10

在阅读了各种 Stackoverflow 帖子和各种文档(包括http://code.google.com/p/google-api-java-client/网站上的一些文档)后,我感到非常困惑。所以有人可以向我解释实现以下目标的最佳方法:

  1. 让用户批准我的应用程序。我真的不在乎这是通过在帐户/设置中访问他们注册的 Google 帐户并批准应用程序(首选方式)或通过调用 Google OAuth 身份验证页面来完成的
  2. 获取可用于与 Google Reader 通信的身份验证令牌

让我感到困惑的另一点 - 我能够使用 AccountManager 批准我的应用程序并从中获取身份验证令牌,但它不适用于 Google Reader。那么如何平衡来自 AccountManager 和 OAuth 的 Account 信息呢?在 AccountManager 设置中获得用户批准后,我还需要对 OAuth 执行任何操作吗?

代码示例会很好,但我会更多地寻找关于所有这些部分如何相互关联的清晰解释

4

2 回答 2

6

The account manager lets you get authentication tokens for different services. There are different concrete implementation under the hood: ClientLogin, OAuth, etc. To get it to work with, say, Google Reader, you need to pass the appropriate token type. For ClientLogin, those are short string like "ah" (App Engine) and "reader" (Google Reader). For OAuth, they are scopes, as defined by each service. So, what are you passing as the authTokenType parameter?

Getting the token is asynchronous, since it may involve network access. If there is a cached token, it will be returned right away, if valid. The flow is not that complicated, see the link above for the pretty picture. Once you get the token, you put it in the appropriate header, and use the API as per the spec.

于 2012-04-10T02:58:29.760 回答
4

这是 AccountManager 上的 Android 培训课程,可能会有所帮助:

http://developer.android.com/training/id-auth/authenticate.html

此外,将 AccountManager 与 Google Reader 结合使用是目前唯一的首选方式。使用 WebView 将用户引导到登录页面不是很安全,据我所知,Google API 不支持使用浏览器(我也不确定 Reader 是否使用 OAuth2)。

于 2012-04-09T22:11:16.760 回答