QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms and devices. Check out our detailed guides to make integration easy and fast.

Users

Learn how to manage your users with QuickBlox.

The user module manages all things related to user accounts handling, authentication, account data, password remind, etc.

Before you begin

  1. Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
  2. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  3. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  4. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

Create user

Create a user using the code snippet below. Only login (or email) and password are required. Other fields are optional.

QBUser user = new QBUser();
user.setLogin("NewUser");
user.setPassword("mypassword");
        
QBUsers.signUp(newUser).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser user, Bundle bundle) {
      
    }

    @Override
    public void onError(QBResponseException e) {
                
    }
});
val user = QBUser()
user.login = "NewUser"
user.password = "mypassword"

QBUsers.signUp(user).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {
        
    }

    override fun onError(e: QBResponseException? {
        
    }
})

Update user

Update a user profile using the following code snippet. If you want to change your password, you need to provide 2 parameters: password and oldPassword. An updated user entity will be returned. If you want to update any other fields of the user (e.g. e-mail or full name), you can do it by calling the updateUser() method.

QBUser user = new QBUser();
user.setEmail("[email protected]");
user.setFullName("UpdatedMyFullname");

QBUsers.updateUser(user).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {
        
    }
});
val user = QBUser()
user.email = "[email protected]"
user.fullName = "UpdatedMyFullname"
        
QBUsers.updateUser(user).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {
        
    }

    override fun onError(e: QBResponseException?) {
        
    }
})

🚧

Pay attention

You must set null into the user's password field if you do not want to change your password, otherwise, you will need to add the user's old password to the oldPassword field.

Set user avatar

You can set a user's avatar. You just need to upload it to the QuickBlox cloud storage and then connect to the user.

private void setAvatar() {
    // Just as example for User model
    final QBUser user = new QBUser();
    user.setId(123);

    // Just create or select any file
    File avatar = new File("");

    // Upload file to the server
    boolean fileIsPublic = false;

    QBContent.uploadFileTask(avatar, fileIsPublic, null, new QBProgressCallback() {
        @Override
        public void onProgressUpdate(int i) {
        // do something to show progress if needed
        }
    }).performAsync(new QBEntityCallback<QBFile>() {
        @Override
        public void onSuccess(QBFile qbFile, Bundle bundle) {
            int uploadedFileID = qbFile.getId();
        
            // Add File to User
            user.setFileId(uploadedFileID);
            updateUser(user);
        }

        @Override
        public void onError(QBResponseException e) {

        }
    });
}

private void updateUser(QBUser user) {
    QBUsers.updateUser(user).performAsync(new QBEntityCallback<QBUser>() {
        @Override
        public void onSuccess(QBUser qbUser, Bundle bundle) {

        }

        @Override
        public void onError(QBResponseException e) {

        }
    });
}
private fun setAvatar() {
    // Just as example for User model
    val user = QBUser()
    user.id = 123

    // Just create or select any file
    val avatar = File("")

    // Upload file to the server
    val fileIsPublic = false

    QBContent.uploadFileTask(avatar, fileIsPublic, null) {
        // do something to show progress if needed
    }.performAsync(object : QBEntityCallback<QBFile> {
        override fun onSuccess(qbFile: QBFile?, bundle: Bundle?) {
            val uploadedFileID = qbFile.id!!

            // Add File to User
            user.fileId = uploadedFileID
            updateUser(user)
        }

        override fun onError(e: QBResponseException?) {

        }
    })
}

fun updateUser(user : QBUser) {
    QBUsers.updateUser(user).performAsync(object : QBEntityCallback<QBUser> {
        override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {

        }

        override fun onError(e: QBResponseException?) {

        }
    })
}

Now, other users can get your avatar.

int userAvatarID = user.getFileId();
QBContent.downloadFileById(userAvatarID, new QBProgressCallback() {
    @Override
    public void onProgressUpdate(int i) {
        // do something to show progress if needed
    }
}).performAsync(new QBEntityCallback<InputStream>() {
    @Override
    public void onSuccess(InputStream inputStream, Bundle bundle) {
        // Receiving input stream
        // Just write an InputStream to a file and show it
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val userAvatarID = user.fileId!!
QBContent.downloadFileById(userAvatarID) {
    // do something to show progress if needed
}.performAsync(object : QBEntityCallback<InputStream> {
    override fun onSuccess(inputStream: InputStream?, bundle: Bundle?) {
        // Receiving input stream
        // Just write an InputStream to a file and show it
    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve users

Retrieve users by ID

To get a list of users by ID for a current account, use the following code snippet.

QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(50);

ArrayList<Integer> usersIDs = new ArrayList<>();
usersIDs.add(123);
usersIDs.add(234);
usersIDs.add(345);
usersIDs.add(456);

QBUsers.getUsersByIDs(usersIDs, pagedRequestBuilder).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
    @Override
    public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val pagedRequestBuilder = QBPagedRequestBuilder()
pagedRequestBuilder.page = 1
pagedRequestBuilder.perPage = 50

val usersIDs = ArrayList<Int>()
usersIDs.add(123)
usersIDs.add(234)
usersIDs.add(345)
usersIDs.add(456)

QBUsers.getUsersByIDs(usersIDs, pagedRequestBuilder).performAsync(object : QBEntityCallback<ArrayList<QBUser>> {
    override fun onSuccess(qbUsers: ArrayList<QBUser>?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Or, you can retrieve a single user if needed.

QBUsers.getUser(qbUser.getId()).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBUsers.getUser(qbUser.id).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve user by login

To get a list of users by login for a current account, use the following code snippet.

String userLogin = qbUser.getLogin();
QBUsers.getUserByLogin(userLogin).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val userLogin = qbUser.login
QBUsers.getUserByLogin(userLogin).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException? {

    }
})

Retrieve user by email

To get a list of users by email for a current account, use the following code snippet.

String usersEmail = qbUser.getEmail();
QBUsers.getUserByEmail(usersEmail).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val usersEmail = qbUser.email
QBUsers.getUserByEmail(usersEmail).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve users by full name

To get a list of users found by the server according to the search query, use the following code snippet.

QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(50);

QBUsers.getUsersByFullName(searchQuery, pagedRequestBuilder).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
    @Override
    public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val pagedRequestBuilder = QBPagedRequestBuilder()
pagedRequestBuilder.page = 1
pagedRequestBuilder.perPage = 50

QBUsers.getUsersByFullName(searchQuery, pagedRequestBuilder).performAsync(object : QBEntityCallback<ArrayList<QBUser>> {
    override fun onSuccess(qbUsers: ArrayList<QBUser>?, bundle: Bundle?) {
    }

    override fun onError(e: QBResponseException?) {
    }
})

Retrieve users by phone number

To get a list of users by phone number for a current account, use the following code snippet.

QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(50);

ArrayList<String> phoneNumbers = new ArrayList<>();
phoneNumbers.add("+380552223344");
phoneNumbers.add("+190229996677");
phoneNumbers.add("78088800444");

QBUsers.getUsersByPhoneNumbers(phoneNumbers, pagedRequestBuilder).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
    @Override
    public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val pagedRequestBuilder = QBPagedRequestBuilder()
pagedRequestBuilder.page = 1
pagedRequestBuilder.perPage = 50

val phoneNumbers = ArrayList<String>()
phoneNumbers.add("+380552223344")
phoneNumbers.add("+190229996677")
phoneNumbers.add("78088800444")

QBUsers.getUsersByPhoneNumbers(phoneNumbers, pagedRequestBuilder).performAsync(object : QBEntityCallback<ArrayList<QBUser>> {
    override fun onSuccess(qbUsers: ArrayList<QBUser>?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve user by external user ID

If you have your own database with users (we call these databases as "external databases"), you can use External User IDExternal User ID - a unique identifier of the user in the integrated external system; used for cross-referencing. For example, a user has an internal user ID within the QuickBlox system and external ID, provided by the integrated external (client) system. When an API call with reference to the user has to be submitted, the user can be referenced by either internal or external identifiers. (ExternalID field) in QBUser model to link users from QuickBlox with users from your external database.

QBUsers.getUserByExternalId(qbUser.getExternalId()).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBUsers.getUserByExternalId(qbUser.externalId).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve users by Facebook ID

To get a list of users by Facebook ID for a current account, use the following code snippet.

QBUsers.getUserByFacebookId(qbUser.getFacebookId()).performAsync(new QBEntityCallback<QBUser>() {
    @Override
    public void onSuccess(QBUser qbUser, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBUsers.getUserByFacebookId(qbUser.facebookId).performAsync(object : QBEntityCallback<QBUser> {
    override fun onSuccess(qbUser: QBUser?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Or, if you want to retrieve several users by Facebook IDs, use the following code lines.

ArrayList<String> facebookIDs = new ArrayList<>();
facebookIDs.add("552223344");
facebookIDs.add("90229996677");
facebookIDs.add("78088800444");

QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(50);

QBUsers.getUsersByFacebookId(facebookIDs, pagedRequestBuilder).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
    @Override
    public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {
        
    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val facebookIDs = ArrayList<String>()
facebookIDs.add("552223344")
facebookIDs.add("90229996677")
facebookIDs.add("78088800444")
  
val pagedRequestBuilder = QBPagedRequestBuilder()
pagedRequestBuilder.page = 1
pagedRequestBuilder.perPage = 50

QBUsers.getUsersByFacebookId(facebookIDs, pagedRequestBuilder).performAsync(object : QBEntityCallback<ArrayList<QBUser>> {
    override fun onSuccess(qbUsers: ArrayList<QBUser>?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Retrieve users by tags

To get a list of users by tags for a current account, use the following code snippet.

QBPagedRequestBuilder pagedRequestBuilder = new QBPagedRequestBuilder();
pagedRequestBuilder.setPage(1);
pagedRequestBuilder.setPerPage(50);
 
ArrayList<String> tags = new ArrayList<>();
tags.add("doctor");
tags.add("english");
tags.add("francias");

QBUsers.getUsersByTags(tags, pagedRequestBuilder).performAsync(new QBEntityCallback<ArrayList<QBUser>>() {
    @Override
    public void onSuccess(ArrayList<QBUser> qbUsers, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
val pagedRequestBuilder = QBPagedRequestBuilder()
pagedRequestBuilder.page = 1
pagedRequestBuilder.perPage = 50
  
val tags = ArrayList<String>()
tags.add("doctor")
tags.add("english")
tags.add("francias")

QBUsers.getUsersByTags(tags, pagedRequestBuilder).performAsync(object : QBEntityCallback<ArrayList<QBUser>> {
    override fun onSuccess(qbUsers: ArrayList<QBUser>?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Delete user

A user can delete himself from the platform.

QBUsers.deleteUser(qbUser.getId()).performAsync(new QBEntityCallback<Void>() {
    @Override
    public void onSuccess(Void aVoid, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBUsers.deleteUser(qbUser.id).performAsync(object : QBEntityCallback<Void> {
    override fun onSuccess(aVoid: Void?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

Reset user password

It's possible to reset a password via email.

QBUsers.resetPassword(qbUser.getEmail()).performAsync(new QBEntityCallback<Void>() {
    @Override
    public void onSuccess(Void aVoid, Bundle bundle) {

    }

    @Override
    public void onError(QBResponseException e) {

    }
});
QBUsers.resetPassword(qbUser.email).performAsync(object : QBEntityCallback<Void> {
    override fun onSuccess(aVoid: Void?, bundle: Bundle?) {

    }

    override fun onError(e: QBResponseException?) {

    }
})

📘

Note

By default, password reset functionality is turned off for Basic, Startup and Growth plans. Contact the sales team.

Updated 2 months ago


What's Next

Chat

Users


Learn how to manage your users with QuickBlox.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.