【发布时间】:2015-12-18 10:38:37
【问题描述】:
当我尝试使用 Plus 的 People Api 访问用户的基本个人资料信息时,收到很多关于我的应用程序崩溃的报告。
这是我的 GoogleApiClient 设置
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(new Scope(Scopes.PROFILE))
.requestScopes(new Scope(Scopes.PLUS_LOGIN))
.requestIdToken(<id_token>)
.requestProfile()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Plus.API)
.addConnectionCallbacks(this)
.build();
在这一行得到一个 IllegalStateException:
Person person = Plus.PeopleApi.getCurrentPerson(mGoogleApiClientPlus)
java.lang.IllegalStateException:GoogleApiClient 有一个可选的 Plus.API 并且未连接到 Plus。使用 GoogleApiClient.hasConnectedApi(Plus.API) 来保护这个调用。
只有在 google 登录返回登录用户后才会调用此代码。那么为什么plus api没有连接呢?
【问题讨论】:
标签: android google-play-services google-api-client google-signin google-plus-signin