QuickBlox登录未使用3.3.1 SDK工作



我已经集成了QuickBlox,一切正常,突然间我遇到了这个错误。我试图了解为什么它来了,但没有得到任何解决方案。

我的代码:

ChatHelper.getInstance().login(user, new QBEntityCallback<Void>() {
            @Override
            public void onSuccess(Void result, Bundle bundle) {
                if(progressDialog!=null)
                    progressDialog.dismiss();
                loginToChat();
                android.util.Log.e(TAG, "QB Chat Login successfully");
            }
            @Override
            public void onError(QBResponseException e) {
                android.util.Log.e(TAG, "Error Login in Home Screen>>>" +e);
                if(progressDialog!=null)
                    progressDialog.dismiss();
            }
        });

private void loginToChat() {
        if(SharedPrefsHelper.getInstance().getQbUser()!=null){
            final QBUser user = SharedPrefsHelper.getInstance().getQbUser();
            ChatHelper.getInstance().loginToChat(user, new QBEntityCallback<Void>() {
                @Override
                public void onSuccess(Void result, Bundle bundle) {
                    android.util.Log.v(TAG, "Chat login onSuccess()");
                }
                @Override
                public void onError(QBResponseException e) {
                    android.util.Log.w(TAG, "Chat login onError(): " + e);

                }
            });
        }
    }

日志猫:

 > D/QBASDK: *********************************************************
    >                                                            *** RESPONSE *** b4c54adf-b802-4327-b74b-96cc3fc5314d ***
    >                                                            STATUS : 201 
    >                                                            HEADERS
    >                                                                X-Runtime=0.012808
    >                                                                Cache-Control=max-age=0, private, must-revalidate
    >                                                                QuickBlox-REST-API-Version=0.1.1
    >                                                                X-Android-Selected-Protocol=http/1.1
    >                                                                QB-Token-ExpirationDate=2017-06-07 13:56:00 UTC
    >                                                                Status=201 Created
    >                                                                X-Request-Id=4a8acb4c-6166-42c0-b85a-a038d61af56b
    >                                                                X-Android-Response-Source=NETWORK 201
    >                                                                Connection=Close
    >                                                                X-Android-Sent-Millis=1496836559559
    >                                                                Content-Type=application/json; charset=utf-8
    >                                                                Date=Wed, 07 Jun 2017 11:56:00 GMT
    >                                                                X-Content-Type-Options=nosniff
    >                                                                Server=openresty/1.9.15.1
    >                                                                ETag=W/"c74341ada523f27d4d495a2443d502a6"
    >                                                                Content-Length=239
    >                                                                Strict-Transport-Security=max-age=31536000max-age=15768000;
    >                                                                X-XSS-Protection=1; mode=block
    >                                                                X-Frame-Options=SAMEORIGIN
    >                                                                X-Android-Received-Millis=1496836559866
    >                                                                Access-Control-Allow-Origin=*
    >                                                            BODY
    >                                                                '{"session":{"application_id":52126,"created_at":"2017-06-07T11:56:00Z","id":170143275,"nonce":-982948609,"token":"76c7ad273008bd4d1a3b87fd80551e046b00cb9e","ts":1496836558,"updated_at":"2017-06-07T11:56:00Z","user_id":0,"_id":"170143275"}}'
    > 06-07 17:25:59.937 4348-4348/com.talktotherapist D/AndroidRuntime:
    > Shutting down VM
    >                                                                    
    >                                                                    
    >                                                                    [ 06-07 17:25:59.937  2014: 4508 D/         ]
    >                                                                     x = 0.110770,  y = 0.138312,  z = 10.251881 06-07 17:25:59.958 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84 06-07 17:26:00.119
    > 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84 06-07 17:26:00.123
    > 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84 06-07 17:26:00.123
    > 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84 06-07 17:26:00.123
    > 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84 06-07 17:26:00.123
    > 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84 06-07 17:26:00.124
    > 4348-4451/com.talktotherapist D/SettingsInterface:  from settings
    > cache , name = android_id , value = 8dc776344146c84
    >                                                                       
    >                                                                       --------- beginning of crash 06-07 17:26:00.127 4348-4348/com.talktotherapist E/AndroidRuntime: FATAL EXCEPTION: main
    >                                                                    Process: com.talktotherapist, PID: 4348
    >                                                                    java.lang.NullPointerException: Attempt to invoke virtual method 'long
    > java.util.Date.getTime()' on a null object reference
    >                                                                        at java.util.Calendar.setTime(Calendar.java:1197)
    >                                                                        at java.text.SimpleDateFormat.formatImpl(SimpleDateFormat.java:527)
    >                                                                        at java.text.SimpleDateFormat.format(SimpleDateFormat.java:829)
    >                                                                        at java.text.DateFormat.format(DateFormat.java:314)
    >                                                                        at
    > com.google.gson.DefaultDateTypeAdapter.write(DefaultDateTypeAdapter.java:88)
    >                                                                        at
    > com.google.gson.DefaultDateTypeAdapter.write(DefaultDateTypeAdapter.java:40)
    >                                                                        at
    > com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
    >                                                                        at
    > com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:125)
    >                                                                        at
    > com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:243)
    >                                                                        at com.google.gson.Gson.toJson(Gson.java:669)
    >                                                                        at com.google.gson.Gson.toJson(Gson.java:648)
    >                                                                        at com.google.gson.Gson.toJson(Gson.java:603)
    >                                                                        at com.google.gson.Gson.toJson(Gson.java:583)
    >                                                                        at com.quickblox.auth.session.b.save(Unknown Source)
    >                                                                        at
    > com.quickblox.auth.session.QBSessionManager.setActiveSession(Unknown
    > Source)
    >                                                                        at
    > com.quickblox.auth.session.QBSessionJsonParser.extractEntity(Unknown
    > Source)
    >                                                                        at
    > com.quickblox.auth.session.QBSessionJsonParser.extractEntity(Unknown
    > Source)
    >                                                                        at com.quickblox.core.parser.QBJsonParser.parse(Unknown Source)
    >                                                                        at
    > com.quickblox.auth.session.Query$VersionEntityCallback.completedWithResponse(Unknown
    > Source)
    >                                                                        at com.quickblox.auth.session.Query.completedWithResponse(Unknown
    > Source)
    >                                                                        at
    > com.quickblox.core.server.HttpRequestRunnable$1.handleMessage(Unknown
    > Source)
    >                                                                        at android.os.Handler.dispatchMessage(Handler.java:111)
    >                                                                        at android.os.Looper.loop(Looper.java:207)
    >                                                                        at android.app.ActivityThread.main(ActivityThread.java:5736)
    >                                                                        at java.lang.reflect.Method.invoke(Native Method)
    >                                                                        at
    > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:910)
    >                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771) 06-07
    > 17:26:00.152 4348-4455/com.talktotherapist D/OpenGLRenderer:
    > ~CanvasContext() 0x7f983cd000 06-07 17:26:00.154
    > 4348-4455/com.talktotherapist D/OpenGLRenderer: ~CanvasContext()
    > 0x7f85c49000

请指导我如何解决登录问题。

请尝试遵循此步骤,它对我非常有用!希望它对您有所帮助!

首先,您需要在QuickBlox中签名。

QBUser user = new QBUser("username", "password");
QBUsers.signIn(user).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {
        Log.e("LOGIN ", "myID =" + qbUser.getId());
    }
    @Override
    public void onError(QBResponseException e) {
        Log.e("LOGIN Error", "error..SIGN IN*****");
    }
});

然后使用该用户对象创建会话然后登录以聊天服务。

以下是代码:

final QBChatService chatService = QBChatService.getInstance();
final QBUser qbuser = new QBUser("username", "password");
QBAuth.createSession(qbuser).performAsync(new QBEntityCallback<QBSession>() {
    @Override
    public void onSuccess(QBSession qbSession, Bundle bundle) {
        user.setId(qbSession.getUserId());
        chatService.login(qbuser, new QBEntityCallback() {
            @Override
            public void onSuccess(Object o, Bundle bundle) {
            }
            @Override
            public void onError(QBResponseException e) {
            }
        });
    }
    @Override
    public void onError(QBResponseException e) {
    }
});

我正在使用QuickBlox版本3.9.1,这对我有用

java

final QBChatService chatService = QBChatService.getInstance();
        final QBUser qbuser = new QBUser("USER_EMAIL", "USER_PASSWORD");
        QBAuth.createSessionByEmail(qbuser).performAsync(new QBEntityCallback<QBSession>() {
            @Override
            public void onSuccess(QBSession qbSession, Bundle bundle) {
                qbuser.setId(qbSession.getUserId());
                chatService.login(qbuser, new QBEntityCallback() {
                    @Override
                    public void onSuccess(Object o, Bundle bundle) {
                        Log.e(TAG, qbSession.getToken() + " , " + qbuser.getEmail());
                    }
                    @Override
                    public void onError(QBResponseException e) {
                    }
                });
            }
            @Override
            public void onError(QBResponseException e) {
            }
        });

kotlin

val chatService = QBChatService.getInstance()
        val qbuser = QBUser("USER_EMAIL", "USER_PASSWORD")
        QBAuth.createSessionByEmail(qbuser).performAsync(object : QBEntityCallback<QBSession> {
            override fun onSuccess(qbSession: QBSession, bundle: Bundle) {
                qbuser.id = qbSession.userId
                chatService.login(qbuser, object : QBEntityCallback<Any> {
                    override fun onSuccess(obj: Any?, bundle: Bundle) {
                        Log.e(TAG, qbSession.token + " , " + qbuser.email)
                    }
                    override fun onError(e: QBResponseException) {
                    }
                })
            }
            override fun onError(e: QBResponseException) {
            }
        })

另一种方法是检查会话参数:

public void loginToChat(final QBUser user, final QBEntityCallback<Void> callback) {
        if (qbChatService.isLoggedIn()) {
            Log.e(TAG, "ChatService Logged In" + qbChatService.isLoggedIn());
            callback.onSuccess(null, null);

,然后从要登录的代码中的任何地方调用此方法:

public void loginChat(int qbUserId) {
        // Initialise Chat service
        QBSessionParameters sessionParameters = QBSessionManager.getInstance().getSessionParameters();
        int user_id = qbUserId;
        String password = null;
        if (sessionParameters.getSocialProvider() != null && sessionParameters.getSocialProvider().equals(QBProvider.FACEBOOK)) {
            password = QBSessionManager.getInstance().getToken();
            Log.e(TAG, "Logged in QBUser -> " + user_id + " ->" + password);
        } else {
            password = sessionParameters.getUserPassword();
            Log.e(TAG, "Logged in QBUser -> " + sessionParameters.getUserEmail());
        }

        final QBUser qbUser = new QBUser();
        qbUser.setId(user_id);
        qbUser.setPassword(password);
        loginToChat(qbUser, new QBEntityCallback<Void>() {
            @Override
            public void onSuccess(Void aVoid, Bundle bundle) {
                Log.e(TAG, "ChatService Logged In" + qbChatService.isLoggedIn());
            }
            @Override
            public void onError(QBResponseException e) {
                Log.e(TAG, "Error -> " + e.getMessage());
            }
        });
    }
            return;
        }
        qbChatService.login(user, callback);
    }

相关内容

  • 没有找到相关文章

最新更新