在从GoogleSignInAPI退出之前,我是否必须致电GoogleApiClient.connect()?

时间:2016-11-30 21:24:42

标签: android google-signin googlesigninapi

Google在Signing Out Users tutorial中说了一句话:

  

注意:在调用signOut之前,您必须确认已调用GoogleApiClient.onConnected。

但是在他们的Firebase implementationold Google implementation上,他们在调用GoogleApiClient.connect()之前调用mGoogleApiClient onConnected()实例上的signOut()不会调用def create @project = Project.find(params[:project_id]) @comment = @project.comments.build(comment_params) @comment.user_id = current_user.id if @comment.save flash[:success] = "Comment created!" redirect_to @project else @projectboard_items = [] flash[:danger] = "Sorry! your comment was not created" render @project #<----- replace this line end end }。

那我该怎么办?文档或示例?

1 个答案:

答案 0 :(得分:0)

答案是肯定的。必须调用GoogleApiClient.connect() - 否则我们将获得IllegalStateException

  

java.lang.IllegalStateException:GoogleApiClient尚未连接。

这就是你退出的方式:

mGoogleClient = new GoogleApiClient.Builder(getContext())
        .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
            @Override
            public void onConnected(@Nullable Bundle bundle) {
            //SIGN OUT HERE
            Auth.GoogleSignInApi.signOut(mGoogleClient).setResultCallback(
                    new ResultCallback<Status>() {
                        @Override
                        public void onResult(Status status) {/*ignored*/}
                    });
            }

            @Override
            public void onConnectionSuspended(int i) {/*ignored*/}
        })
        .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
            @Override
            public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
            /*ignored*/
            }
        })
        .addApi(Auth.GOOGLE_SIGN_IN_API) //IMPORTANT!!!
        .build();

mGoogleClient.connect();

所以我猜他们的示例代码中缺少这部分。

相关问题