用户资料
获取与更新用户资料;资料由应用自有用户体系维护,IM 服务不强制托管。
平台调用风格
双语言同契约:Swift 用 async -> RcResult<T>(错误码在 RcResult.code,返回 null 的 op 用 RcResult<Void>);Objective-C 用 - (void)opWithParam:... completion:(void (^)(RcResult *))completion,回调在主线程投递。
接口一览
| 操作 | 语义 | 传输 | 返回 |
|---|---|---|---|
getUserProfile | 查询用户资料。 | REST(客户端) | UserProfile |
updateMyUserProfile | 修改本人资料(name/avatarUrl)。 | REST(客户端) | UserProfile |
本页 2 个操作,其中 2 个在本平台绑定中声明了方法签名。
跨端方法名
| 操作 | Android | Web | Electron | macOS | Flutter | Native (C ABI) | iOS |
|---|---|---|---|---|---|---|---|
getUserProfile | getUserProfile | getUserProfile | getUserProfile | getUserProfile | getUserProfile | — | func |
updateMyUserProfile | updateMyUserProfile | updateMyUserProfile | updateMyUserProfile | updateMyUserProfile | updateMyUserProfile | — | func |
方法名在 GA 平台之间保持一致(规则 A);Native C ABI 只覆盖部分操作,其余操作以 — 标注。
getUserProfile
查询用户资料。
func getUserProfile(userId: String) async -> RcResult<IMPUserProfile>参数
| 参数 | 类型 | 说明 |
|---|---|---|
userId | string | 必填;用户 ID |
返回
UserProfile 用户资料
示例(Swift / Objective-C)
let res = await client.getUserProfile(userId: "user2")
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }[client getUserProfileWithUserId:@"user2" completion:^(IMPOSResult *result) {
if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];错误码
| 错误码 | 名称 | 分类 | HTTP | 可重试 | 说明 |
|---|---|---|---|---|---|
1001 | INVALID_PARAMETER | 客户端 / 参数 / 权限 | 400 | 否 | 参数错误 |
1003 | FORBIDDEN | 客户端 / 参数 / 权限 | 403 | 否 | 无权限 |
1004 | USER_NOT_FOUND | 客户端 / 参数 / 权限 | 404 | 否 | 用户不存在 |
updateMyUserProfile
修改本人资料(name/avatarUrl)。
func updateMyUserProfile(profile: IMPUserProfileUpdate) async -> RcResult<IMPUserProfile>参数
| 参数 | 类型 | 说明 |
|---|---|---|
profile | {name?:string, avatarUrl?:string} | 必填;待更新的资料字段:{ name?:string, avatarUrl?:string } |
返回
UserProfile 用户资料
示例(Swift / Objective-C)
let res = await client.updateMyUserProfile(profile: IMPUserProfileUpdate())
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }[client updateMyUserProfileWithProfile:@{ @"name": @"产品群", @"avatarUrl": @"value" } completion:^(IMPOSResult *result) {
if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];错误码
| 错误码 | 名称 | 分类 | HTTP | 可重试 | 说明 |
|---|---|---|---|---|---|
1001 | INVALID_PARAMETER | 客户端 / 参数 / 权限 | 400 | 否 | 参数错误 |
1003 | FORBIDDEN | 客户端 / 参数 / 权限 | 403 | 否 | 无权限 |
相关文档
- 功能列表:103 个操作与签名
- 状态码:错误码与重试策略
- API 参考:类与成员
- IMLib 集成指南