Quickblox 登录无法使用 3.3.1 sdk

Posted

技术标签:

【中文标题】Quickblox 登录无法使用 3.3.1 sdk【英文标题】:Quickblox login is not working using 3.3.1 sdk 【发布时间】:2017-06-01 16:24:29 【问题描述】:

我已集成 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

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

【问题讨论】:

你好 Ash,请为 QuickBlox git 存储库 github.com/QuickBlox/quickblox-android-sdk/issues 创建问题,并在收到此错误时附加更多带有服务器请求和响应的日志,它们可以更快地帮助您 请尝试上传您的具体完整代码,以便其他人可以正确帮助您。 @ValentynTereshchenko,我在 github.com 上创建了问题。 github.com/QuickBlox/quickblox-android-sdk/issues/412 【参考方案1】:

请尝试按照以下步骤操作,它对我非常有效! 希望对您有所帮助!

首先您需要登录 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) 

    
);

【讨论】:

我已经更新了logcat,请检查错误,我已经尝试过你的答案但它不起作用 hii @Ash 你能发布你正在使用的 loginToChat() 方法的代码吗..! 嗨@Rucha,我已经更新了问题并添加了 loginToChat() @Ash In log cat user id catch my eye(user id: 0) 所以请确保用户 id 或仔细检查您遗漏了什么或什么!你的代码对我来说似乎很完美,我找不到任何问题。你也可以试试我的代码,它完美无缺。很高兴能帮助你! :) 嗨@Rucha,你集成了群聊吗?如果是的话,如果聊天窗口没有刷新,你能建议我,那么我需要调用哪种方法【参考方案2】:

我正在使用 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) 

            
        );

科特林

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);

然后在代码中你想登录QBChatService的任何地方调用这个方法:

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);
    

【讨论】:

使用您的代码,如果我用错误的密码设置 qbUser:createSession 返回错误“未授权”。如果我使用正确的密码设置 qbUser,createSession 会进入其 onSuccess 回调,但 chatService.login 会进入其 onError 并显示错误:身份验证失败,请检查用户的 ID 和密码。我正在使用您完全相同的代码,并且总是收到最后一个错误。知道我做错了什么吗? @yalematta 您需要先检查您的会话是否处于活动状态 @yalematta 更新了我的答案,立即查看,希望对您有所帮助! 即使在检查 QBSessionParameters 后我仍然收到相同的错误:身份验证失败,请检查用户 ID 和密码 @yalematta 发布您的代码 sn-p,我会尝试检查

以上是关于Quickblox 登录无法使用 3.3.1 sdk的主要内容,如果未能解决你的问题,请参考以下文章

无法登录 QuickBlox iOS 13

无法使用 quickblox(iOS)登录 facebook

Quickblox iOS - 登录正常。无法让 Facebook 弹出窗口出现?

QuickBlox - 无法连接聊天

Quickblox:无法获得推送通知

在 IOS 中使用 QuickBlox 视频聊天,无需登录或密码