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.

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.

Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.

Before you begin

  1. 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.
  2. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  3. 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("johnsmith");
user.setPassword("johnPassword");
        
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 = "johnsmith"
user.password = "johnPassword"

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

    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?) {

    }
})

📘

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

Update user

Update a user profile by calling the updateUser() method. If you want to change your password, you need to provide 2 parameters: password and newPassword. The updated user entity will be returned.

🚧

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.

You can update any other field of the user using the updateUser() method. Thus, the snippet below shows how to update a tagList and customData fields.

// set user's tag or tags
StringifyArrayList<String> userTags = new StringifyArrayList<>();
userTags.add("tagOne");
userTags.add("tagTwo");

user.setTags(userTags);

// set user's custom data
JSONObject jsonObject = new JSONObject();
try {
    jsonObject.put("name", "John");
    jsonObject.put("age", 31);
    jsonObject.put("city", "New York");
} catch (JSONException e) {
    
}

user.setCustomData(jsonObject.toString());

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

    @Override
    public void onError(QBResponseException e) {
        
    }
});
// set user's tag or tags
val userTags = StringifyArrayList<String>()
userTags.add("tagOne")
userTags.add("tagTwo")

user.tags = userTags

// set user's custom data
val jsonObject = JSONObject()
try {
    jsonObject.put("name", "John")
    jsonObject.put("age", 31)
    jsonObject.put("city", "New York")
} catch (e: JSONException) {
  
}

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

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

Field

Required

Description

tags

no

User tags. An array of Strings. A tag must include alphanumeric characters only and start with a letter. The tag must be at least 3 and no more than 15 characters long. There are no spaces in the tag format. For example, the "tagOne" format is correct while the "tag one" format is incorrect.

If more that 10 tags are provided, an error is returned: tag list should contain maximum 10 tags.

customData

no

User custom data. Should be a String. You can convert any data types to String, for example, JSON, XML , etc.

Set user avatar

To set a user avatar, just create and upload a file to the QuickBlox cloud storage and connect it to the user.

To create a file to QuickBlox cloud storage, you should overwrite the file from the device file system to a java.io.File and then write it to the avatar. Then, upload the file to the QuickBlox cloud storage by calling the uploadFileTask() method and passing the avatar to it. Now that the file is uploaded, get the ID of the uploaded file. See this section to learn more about file upload functionality in details.

To connect the file to the user, set the ID of the uploaded file to the fileId field of the user and call the updateUser() method. As a result, the user avatar gets updated.

private void setAvatar() {
    // Just as example for User model
    final QBUser user = new QBUser();
    user.setId(123);
 
    String tags = null; 
  
    // Create file
    File avatar = new File("path to file");
    // Some logic for write file by OutputStream and InputStream.
  
    // Upload file to the server
    boolean fileIsPublic = false;

    QBContent.uploadFileTask(avatar, fileIsPublic, tags, 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
    
    val tags:String? = null
      
    // Create file
    val avatar = File("path to file")
    // Some logic for write file by OutputStream and InputStream.
   
    // Upload file to the server
    val fileIsPublic = false

    QBContent.uploadFileTask(avatar, fileIsPublic, tags) {
        // 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?) {

        }
    })
}

Pass the following arguments to the updateUser() method:

Argument

Required

Description

user

yes

Specifies user fields that should be set.

Now, other users can get your avatar by calling the downloadFileById() method.

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?) {

    }
})

Argument

Required

Descriotion

userAvatarID

yes

File unique identifier.

Updated 15 days 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.