我的代码如下,但运行会出错。请大神看看,给一点建议
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(Scope(Scopes.PROFILE))
.requestScopes(Scope(Scopes.PLUS_LOGIN))
.requestProfile()
.requestEmail()
.build()
以下是建立连接的代码
mClient = GoogleApiClient.Builder(this.activity)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Fitness.HISTORY_API)
.addScope(Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
.addScope(Scope(Scopes.FITNESS_BODY_READ_WRITE))
.addConnectionCallbacks(
object : GoogleApiClient.ConnectionCallbacks {
override fun onConnected(bundle: Bundle?) {
if (insertData) {
InsertAndVerifyDataTask(weight).execute()
}
}
override fun onConnectionSuspended(i: Int) {
if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
LogUtils.log("ysq", "Connection lost. Cause: Network Lost.")
} else if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
LogUtils.log("ysq", "Connection lost. Reason: Service Disconnected")
}
}
}
)
.enableAutoManage(this.activity, 0, {
result ->
LogUtils.log("ysq", "Google Play services connection failed. Cause: " + result.toString())
})
.build()
} catch (e: Exception) {
e.printStackTrace()
}
错误:
java.lang.IllegalStateException: Must not set scopes in GoogleApiClient.Builder when using Auth.GOOGLE_SIGN_IN_API. Set account in GoogleSignInOptions.Builder instead.