Manage users
This document applies to the following platforms: iOS, Android, macOS, Windows and Web.
ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of user management, allows users to update their personal profile, such as username, and status updates.
Implementation Process
Manage the extended field
The ZIM SDK provides user extended fields to describe additional properties of users. Developers can use extended fields to customize user attributes through the UpdateUserExtendedData interface. The usage of extended fields can be defined by developers, and the SDK will only pass the fields without any further processing.
After modifying the extended field properties, users can receive the modification results through ZIMUserExtendedDataUpdatedCallback.
// Modify the user information extended field
String newUserExtendedData = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";
zim.updateUserExtendedData(newUserExtendedData, new ZIMUserExtendedDataUpdatedCallback() {
@Override
public void onUserExtendedDataUpdated(String extendedData, ZIMError errorInfo) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// Modification succeeded
}
}
});
1
// Update the extended field of user information.
NSString *extendedData = @"";
[zim updateUserExtendedData:extendedData callback:^(NSString * _Nonnull extendedData, ZIMError * _Nonnull errorInfo) {
}];
1
// Modify user information extension fields
String newUserExtendedData = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";
try {
ZIMUserExtendedDataUpdatedResult result =
await ZIM.getInstance()!.updateUserExtendedData(newUserExtendedData);
} on PlatformException catch (onError) {
//Here is the logic of write operation failure according to the return value of onError
}
1
std::string new_user_extended_data = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";
zim_->updateUserExtendedData(new_user_extended_data, [=](const std::string &extended_data, zim::ZIMError error_info){
if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
// Modification successful
}
});
1
var extendedData = JSON.stringify({ age: 18, birthdy: '2000-01-01' });
zim.updateUserExtendedData(extendedData)
.then(function ({ extendedData }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
var extendedData = JSON.stringify({ age: 18, birthdy: '2000-01-01' });
zim.updateUserExtendedData(extendedData)
.then(function ({ extendedData }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
string newUserExtendedData = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";
ZIM.GetInstance().UpdateUserExtendedData(newUserExtendedData,
(string extendedData, ZIMError errorInfo) => {
if(errorInfo.code == ZIMErrorCode.Success) {
// Operation successful
}
});
1
Modify User Name
The user name userName
is a string used to describe the user's nickname. Developers can configure it through the ZIMUserInfo object. The ZIM SDK supports users to modify their user names after logging in through the UpdateUserName interface.
After modifying the user name, users can receive the modification results through ZIMUserNameUpdatedCallback.
// Modify the user name
// The userName is a string with a maximum length of 256 bytes, and there are no special character restrictions.
String newUserName = "new_name";
zim.updateUserName(newUserName, new ZIMUserNameUpdatedCallback() {
@Override
public void onUserNameUpdated(String userName, ZIMError errorInfo) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// Modification succeeded
}
}
});
1
// Modify the username.
// The `userName` parameter can contain up to 256 bytes in length, with no limit on characters.
NSString *userName = @"";
[zim updateUserName:userName callback:^(NSString * _Nonnull userName, ZIMError * _Nonnull errorInfo) {
}];
1
// modify user name
// userName A string of up to 256 bytes, with no special character restrictions.
try {
ZIMUserNameUpdatedResult result =
await ZIM.getInstance()!.updateUserName('userName');
//The logic of successful modification is written here
} on PlatformException catch (onError) {
// Write and modify the failure logic according to onError
}
1
// Modify user name
// userName is a string with a maximum of 256 bytes, no special character restrictions.
std::string new_user_name = "new_name";
zim_->updateUserName(new_user_name, [=](const std::string &userName, const zim::ZIMError &errorInfo){
if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
// Modification successful
}
});
1
// Modify user name
// userName is a string with a maximum of 256 bytes, no special character restrictions.
var userName = 'new_name';
zim.updateUserName(userName)
.then(function ({ userName }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
// Modify user name
// userName is a string with a maximum of 256 bytes, no special character restrictions.
var userName = 'new_name';
zim.updateUserName(userName)
.then(function ({ userName }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
// Modify user name
// userName is a string with a maximum of 256 bytes, no special character restrictions.
string newUserName = "new_name";
ZIM.GetInstance().UpdateUserName(newUserName, (string userName, ZIMError errorInfo) => {
if(errorInfo.code == ZIMErrorCode.Success) {
// Operation successful
}
});
1
Set User Avatar
The ZIM SDK supports users to set or modify their avatars after logging in through the UpdateUserAvatarUrl interface.
After setting the user avatar, users can receive the setting results through the ZIMUserAvatarUrlUpdatedCallback.
// Set the user avatar
// The URL has a maximum length of 500 bytes, and there are no special character restrictions.
String userAvatarUrl = "xxx";
zim.updateUserAvatarUrl(userAvatarUrl, new ZIMUserAvatarUrlUpdatedCallback() {
@Override
public void onUserAvatarUrlUpdated(String userAvatarUrl, ZIMError errorInfo) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// Setting succeeded
}
}
});
1
// Set the user avatar.
// The URL can contain up to 500 bytes in length, with no limit on characters.
NSString *userAvatarUrl = @"";
[zim updateUserAvatarUrl callback:^(NSString * _Nonnull userAvatarUrl, ZIMError * _Nonnull errorInfo) {
}];
1
// modify user name
// userAvatarUrl A string of up to 500 bytes, with no special character restrictions.
try {
ZIMUserAvatarUrlUpdatedResult result =
await ZIM.getInstance()!.updateUserAvatarUrl('userAvatarUrl');
//The logic of successful modification is written here
} on PlatformException catch (onError) {
// Write and modify the failure logic according to onError
}
1
// URL maximum 500 bytes, no special character restrictions
std::string user_avatar_url = "";
zim_->updateUserAvatarUrl(user_avatar_url, [=](const std::string &userAvatarUrl, zim::ZIMError error_info){
if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
// Operation successful
}
});
1
// URL maximum 500 bytes, no special character restrictions
var userAvatarUrl = 'https://xxxx';
zim.updateUserAvatarUrl(userAvatarUrl)
.then(function ({ userAvatarUrl }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
// URL maximum 500 bytes, no special character restrictions
var userAvatarUrl = 'https://xxxx';
zim.updateUserAvatarUrl(userAvatarUrl)
.then(function ({ userAvatarUrl }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
// URL maximum 500 bytes, no special character restrictions
string userAvatarUrl = "xxx";
ZIM.GetInstance().UpdateUserAvatarUrl(userAvatarUrl, (string userAvatarUrl, ZIMError errorInfo) => {
if(errorInfo.code == ZIMErrorCode.Success) {
// Operation successful
}
});
1
Users can query the full information of specified users, including user names and user extended fields, through the QueryUsersInfo interface. Only in this interface can users obtain user avatar URLs and user extended field information.
After querying the information, users can receive the query results through the ZIMUsersInfoQueriedCallback.
// Query user information
// Usage restrictions: The number of UserID to be queried in a single call to the interface cannot exceed 10; within 10 seconds, the cumulative total number of UserID queried by multiple calls to the interface cannot exceed 10.
ArrayList<String> userIDList = new ArrayList<>();
userIDList.add("user_id_1");
ZIMUsersInfoQueryConfig config = new ZIMUsersInfoQueryConfig();
config.isQueryFromServer = false;
zim.queryUsersInfo(userIDList, config, new ZIMUsersInfoQueriedCallback() {
@Override
public void onUsersInfoQueried(ArrayList<ZIMUserFullInfo> userList, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
if(errorInfo.code == ZIMErrorCode.SUCCESS) {
// Query succeeded
}
}
});
1
// Query user information.
// Restrictions: You can query up to 10 user IDs per call or by multiple calls within 10 seconds.
[self.zim queryUsersInfo:@[@"userID_1",@"userID_2"] callback:^(NSArray<ZIMUserFullInfo *> * _Nonnull userList, NSArray<ZIMErrorUserInfo *> * _Nonnull errorUserList, ZIMError * _Nonnull errorInfo) {
}];
1
// Query user information
// Usage restrictions: The number of UserID queries in a single API call cannot exceed 10; within 10 seconds, the cumulative total number of UserID queries in multiple API calls cannot exceed 10.
try {
ZIMUserInfoQueryConfig config = ZIMUserInfoQueryConfig();
config.isQueryFromServer = false; // Set to true if querying from the server, set to false if querying from local data
ZIMUsersInfoQueriedResult result =
await ZIM.getInstance()!.queryUsersInfo(['userID_1', 'userID_2'], config);
// Write logic for successful query here
} on PlatformException catch (onError) {
// Write logic for failed query based on onError
}
1
// Query user information
// Usage restrictions: The number of UserID to be queried in a single call to the interface cannot exceed 10;
// within 10 seconds, the cumulative total number of UserID queried by multiple calls to the interface cannot exceed 10.
std::string target_user_id = "user_id_1";
std::vector<std::string> user_id_list;
user_id_list.push_back(target_user_id);
zim::ZIMUsersInfoQueryConfig config;
// false is for local query, which prioritizes returning data from the local database.
// If there is no corresponding user information in the local database and the query frequency limit has not been reached, it will automatically upgrade to query from the server.
// true is for server query, which prioritizes pulling user information from the server.
// When the query frequency limit is reached, user information that has not been queried from the server will attempt to return data from the local database.
config.isQueryFromServer = false;
zim_->queryUsersInfo(user_id_list, config, [=](const std::vector<zim::ZIMUserFullInfo> &userList, const std::vector<zim::ZIMErrorUserInfo> &errorUserList, const ZIM::ZIMError &errorInfo) {
if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
// Query succeeded
}
});
1
// Limitations: The number of UserID queries in a single API call cannot exceed 10; Within 10 seconds, the cumulative total of all UserID queries cannot exceed 10.
var userIDs = ['id1', 'id2'];
zim.queryUsersInfo(userIDs, { isQueryFromServer: false })
.then(function ({ userList, errorUserList }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
// Limitations: The number of UserID queries in a single API call cannot exceed 10; Within 10 seconds, the cumulative total of all UserID queries cannot exceed 10.
var userIDs = ['id1', 'id2'];
zim.queryUsersInfo(userIDs, { isQueryFromServer: false })
.then(function ({ userList, errorUserList }) {
// Operation successful
})
.catch(function (err) {
// Operation failed
});
1
// Limitations: The number of UserID queries in a single API call cannot exceed 10; Within 10 seconds, the cumulative total of all UserID queries cannot exceed 10.
List<string> userIDList = new List<string>();
userIDList.Add("user_id_1");
ZIMUsersInfoQueryConfig config = new ZIMUsersInfoQueryConfig();
ZIM.GetInstance().QueryUsersInfo(userIDList, config, (ZIMUserFullInfo[] userList, ZIMErrorUserInfo[] errorUserList, ZIMError errorInfo) => {
if (errorInfo.code == ZIMErrorCode.Success)
{
// Operation successful
}
});
1