有奖捉虫:办公协同&微信生态&物联网文档专题 HOT

功能描述

用户可以设置和获取个人的昵称、头像、签名等资料信息,也可以获取到陌生人的资料信息。

关系链事件监听器

目前提供的关系链事件如下:
监听器
解释
SetOnAddFriendCallback
设置添加好友的回调。
SetOnDeleteFriendCallback
设置删除好友的回调。
SetUpdateFriendProfileCallback
设置更新好友资料的回调。
SetFriendAddRequestCallback
设置好友添加请求的回调。
SetFriendApplicationListDeletedCallback
设置好友申请被删除的回调。
SetFriendApplicationListReadCallback
设置好友申请已读的回调。
SetFriendBlackListAddedCallback
设置黑名单新增的回调。
SetFriendBlackListDeletedCallback
设置黑名单删除的回调。
当不想再接收关系链事件时,可调用相同回调函数传入 null 移除关系链事件监听器。
注意
只有预先设置好关系链事件监听器,才能正常接收到下文中的各种事件通知。

用户资料管理

查询和修改自己的资料

您可以调用 ProfileGetUserProfileList (点击查看详情) 接口查询个人资料,其中参数 friendship_getprofilelist_param_identifier_array 需填入自己的 UserID。
您可以调用 ProfileModifySelfUserProfile (点击查看详情) 接口修改个人资料。
示例代码如下:
// 获取个人资料
FriendShipGetProfileListParam param = new FriendShipGetProfileListParam
{
friendship_getprofilelist_param_identifier_array = new List<string>
{
"self_user_id"
}
};
TIMResult res = TencentIMSDK.ProfileGetUserProfileList(param, (int code, string desc, List<UserProfile> profile, string user_data)=>{
// 处理异步逻辑
});

// 设置个人资料
UserProfileItem param = new UserProfileItem{
user_profile_item_nick_name = "new_nick_name"
};
TIMResult res = TencentIMSDK.ProfileGetUserProfileList(param, (int code, string desc, string user_data)=>{
// 处理异步逻辑
});


查询非好友用户资料

您可以调用 ProfileGetUserProfileList (点击查看详情) 接口查询非好友资料,其中参数 friendship_getprofilelist_param_identifier_array 填入非好友的 UserID 即可。
说明
不能修改非好友的资料。

查询和修改好友资料

您可以调用 FriendshipGetFriendsInfo (点击查看详情) 接口查询指定的好友资料,从回调信息中通过 FriendInfoGetResultfriendship_friend_info_get_result_relation_type 字段可以得到该用户与自己的关系:
relation
与自己的关系
TIMFriendshipRelationType.kTIMFriendshipRelationType_None
表示不是好友。
TIMFriendshipRelationType.kTIMFriendshipRelationType_BothFriend
表示互为好友。
TIMFriendshipRelationType.kTIMFriendshipRelationType_InMyFriendList
表示对方在我的好友列表中。
TIMFriendshipRelationType.kTIMFriendshipRelationType_InOtherFriendList
表示我在对方的好友列表中。
// 获取好友信息
TIMResult res = TencentIMSDK.FriendshipGetFriendsInfo(friend_userids, (int code, string desc, List<FriendInfoGetResult> result, string user_data)=>{
// 处理异步逻辑
});
您可以调用 FriendshipModifyFriendProfile (点击查看详情) 接口修改好友备注等资料。
// 设置好友信息
FriendshipModifyFriendProfileParam param = new FriendshipModifyFriendProfileParam
{
friendship_modify_friend_profile_param_identifier = "friend_userid",
friendship_modify_friend_profile_param_item = new FriendProfileItem
{
friend_profile_item_remark = "nickname" // 好友备注
}
};
TIMResult res = TencentIMSDK.FriendshipModifyFriendProfile(param, (int code, string desc, string user_data)=>{
// 处理异步逻辑
});

常见问题

增强版获取用户资料为什么不是最新的?

增强版 SDK 中用户资料的更新分好友和陌生人两种情况:
好友资料:由于好友资料更新时,后台会主动向 SDK 发送系统通知,因此好友资料可以实时更新。
陌生人资料:陌生人资料更新时,由于没有好友关系,后台无法向 SDK 发送系统通知,因此无法实时更新;为了避免每次获取用户资料都向后台发起网络请求,SDK 增加了缓存逻辑,对同一个用户主动向后台拉取资料的时间间隔为 10 分钟。

交流与反馈

点此进入IM社群,享有专业工程师的支持,解决您的难题