相关疑难解决方法(0)

访问Google API - GoogleAccountCredential.usingOAuth2与GoogleAuthUtil.getToken()

最近,我一直在使用Android上的Google API,特别是Google Analytics,AdSense和Tasks API.

我见过Google提供的一些示例,他们使用此语句获取GoogleAccountCredential对象

https://code.google.com/p/google-api-java-client/source/browse/tasks-android-sample/src/main/java/com/google/api/services/samples/tasks/android/ TasksSample.java?repo=samples

credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(TasksScopes.TASKS));

但是,如果我查看以下文档:
http://developer.android.com/google/auth/http-auth.html
http://developer.android.com/google/play-services/auth.html

他们都提到了下面用于获取令牌的方法:
token = GoogleAuthUtil.getToken(mActivity, mEmail, mScope);

我很困惑在哪种场景中使用哪一个以及为什么.我一直在使用Method no.1成功而无需在首选项中保留令牌(我猜这是由GoogleAccountCredential自动完成的)

  1. 任何人都可以告诉我为什么有人会使用第一种方法而不是第二种方法?

  2. 如何在第一种方法中访问身份验证令牌?

android google-api oauth-2.0 google-api-java-client

38
推荐指数
2
解决办法
2万
查看次数