简体   繁体   中英

Quickblox Android SDK : Login with facebook token issue

I'm using Quickblox in my app and I can't signIn an user with Facebook token, here's how I create QB Session which works fine:

public static void createSession(final QBEntityCallback callback){
    QBAuth.createSession(new QBEntityCallbackImpl<QBSession>() {
        @Override
        public void onSuccess(QBSession result, Bundle params) {
            callback.onSuccess();
        }

        @Override
        public void onError(List<String> errors) {
            Log.e("QBSession", "error " + errors.toString());
        }
    });
}

When the user log in with facebook, the result token is not null but when I do this:

public static void registerUser(AccessToken currentAccessToken, final QBEntityCallbackImpl callback) {

    if (currentAccessToken == null)return;

    QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, currentAccessToken.getToken(), null, new QBEntityCallbackImpl<QBUser>() {
        @Override
        public void onSuccess(QBUser user, Bundle args) {
            callback.onSuccess(user, args);
        }

        @Override
        public void onError(List<String> errors) {
            Log.e("error", "is " + errors.toString());
        }
    });
}

I get this in the logcat:

E/error﹕ is [base Login or email required]

Here is the documents.

Any suggestions?

UPDATE

In case it could help some people, here's how I do it now:

  • First, I sign up this way, where Profile is the object from the facebook login callback:

      public static void signUpUser(Profile newProfile, final QBEntityCallbackImpl callback){ QBUser qbUser = new QBUser(); qbUser.setFullName(newProfile.getName()); qbUser.setLogin(newProfile.getId()); qbUser.setPassword(newProfile.getId()); qbUser.setFacebookId(newProfile.getId()); QBUsers.signUp(qbUser, new QBEntityCallbackImpl<QBUser>() { @Override public void onSuccess(QBUser result, Bundle params) { callback.onSuccess(result, params); } @Override public void onError(List<String> errors) { callback.onError(errors); } }); 

    }

  • Once the user is created, he can now login using the signUpUsingSocialProvider :

     public static void signInUser(AccessToken currentAccessToken, final QBEntityCallbackImpl callback) { if (currentAccessToken == null)return; String facebookAccessToken = currentAccessToken.getToken(); QBUsers.signInUsingSocialProvider(QBProvider.FACEBOOK, facebookAccessToken, null, new QBEntityCallbackImpl<QBUser>() { @Override public void onSuccess(QBUser user, Bundle args) { callback.onSuccess(user, args); } @Override public void onError(List<String> errors) { callback.onError(errors); } }); 

    }

So, the trick was to create the user the normal way before login with Facebook. Then it's possible for this user to login on another device just using his Facebook session.

You don't need to create a user when you would like to use social login

Just do the following things:

  1. createSession
  2. signInUsingSocialProvider

don't need to call signUp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM