使用Auth.GOOGLE_SIGN_IN_API时,不得在GoogleApiClient.Builder中设置范围。请改为在GoogleSignInOptions.Builder中设置帐户

时间:2017-08-22 10:27:10

标签: java android google-fit

我的代码如下,但运行会出错。请大神看看,给一点建议

            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.

0 个答案:

没有答案