错误验证数据QuickBlox - Android

时间:2016-01-16 08:25:49

标签: android quickblox

我正在使用QuickBlox SDK,使用此SDK我尝试在Facebook上登录。我已经访问了像this这样的stackoverflow上的一些有用的链接,但它并没有帮助我。这是我的代码段。

QBAuth.createSession(new QBEntityCallbackImpl<QBSession>() {
    @Override
    public void onSuccess(QBSession session, Bundle params) {
        String token = session.getToken();
        QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, token, null, new QBEntityCallbackImpl<QBUser>() {
            @Override
            public void onSuccess(QBUser user, Bundle args) {
                Toast.makeText(getApplicationContext() , "Success" ,Toast.LENGTH_SHORT).show();
            }
            @Override
            public void onError(List<String> errors) {
                Toast.makeText(getApplicationContext() , "onError" ,Toast.LENGTH_SHORT).show();
            }
        });
    }
    @Override
    public void onError(List<String> errors) {

    }
});

LogCat详细信息:

Access-Control-Allow-Origin=*
    Cache-Control=no-cache
    Connection=keep-alive
    Content-Length=38
    Content-Type=application/json; charset=utf-8
    Date=Sat, 16 Jan 2016 08:14:28 GMT
    QB-Token-ExpirationDate=2016-01-16 10:14:03 UTC
    QuickBlox-REST-API-Version=0.1.1
    Server=nginx/1.8.0
    Status=422 Unprocessable Entity
    X-Rack-Cache=invalidate, pass
    X-Request-Id=c350c40caa43dae4fa962da7f2e8e389
    X-Runtime=0.132058
    X-UA-Compatible=IE=Edge,chrome=1
  BODY
    '{"errors":["Bad Authentication data"]}'

2 个答案:

答案 0 :(得分:2)

您使用了错误的令牌

它应该是Facebook令牌

请使用本指南将Facebook SDK集成到您的应用

https://developers.facebook.com/docs/android/getting-started

https://developers.facebook.com/docs/facebook-login/android

答案 1 :(得分:2)

最后我得到了上述问题的答案,我在方法 QBUsers.signInUsingSocialProvider()中传递了错误的AccessToken。在使用

成功登录facebook后,我需要获取AccessToken
AccessToken accessToken = loginResult.getAccessToken();

然后我需要在 QBUsers.signInUsingSocialProvider()

中传递此accessToken

这是我的完整代码:

    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken = loginResult.getAccessToken();
            facebooklogin(accessToken);
        }

        @Override
        public void onCancel() {
            // App code
            Toast.makeText(getApplicationContext(), "Cancel", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Toast.makeText(getApplicationContext(), "Error-Check Network Connection", Toast.LENGTH_SHORT).show();
        }

    });

   public void facebooklogin(final AccessToken accessToken) {

        QBAuth.createSession(new QBEntityCallbackImpl<QBSession>() {
            @Override
            public void onSuccess(QBSession session, Bundle params) {

                String token = accessToken.getToken();

                QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, token, null, new QBEntityCallbackImpl<QBUser>() {
                    @Override
                    public void onSuccess(QBUser user, Bundle args) {
                        Toast.makeText(getApplicationContext(), "Success QB", Toast.LENGTH_SHORT).show();
                    }
                    @Override
                    public void onError(List<String> errors) {
                        Toast.makeText(getApplicationContext(), "onError QB", Toast.LENGTH_SHORT).show();
                    }
                });
            }
            @Override
            public void onError(List<String> errors) {
                Toast.makeText(getApplicationContext(), "onError", Toast.LENGTH_SHORT).show();
            }
        });


    }