FriendshipSearchFriends
introduction
Search friend
Return locally stored user profile, and by the friendship_friend_info_get_result_relation_type field in FriendInfoGetResult to judge whether the user is a friend.
Only locally stored users can be searched for, such as contacts or user profiles that have been pulled.
You can set the search keyword friendship_search_param_keyword_list and specify the search scope to set whether to search by the userID, nickName, and remark fields of a user.
Parameter details
overload1
Parameter name | Parameter type | Required | Description |
---|---|---|---|
json_search_friends_param | FriendSearchParam | Required | FriendSearchParam |
callback | ValueCallback< List< FriendInfoGetResult > > | Required | Asynchronous callback The format of json_param in the return value is json |
overload2
Parameter name | Parameter type | Required | Description |
---|---|---|---|
json_search_friends_param | FriendSearchParam | Required | FriendSearchParam |
callback | ValueCallback< string > | Required | Asynchronous callback The format of json_param in the return value is string |
Returned template
TIMResult
The parameters of the callback function after successfully calling the API:
code:int
desc:string
json_param:
'[
{
"friendship_friend_info_get_result_error_code": 0,
"friendship_friend_info_get_result_error_message": "OK",
"friendship_friend_info_get_result_field_info": {
"friend_profile_add_source": "",
"friend_profile_add_time": 0,
"friend_profile_add_wording": "",
"friend_profile_custom_string_array": [{
"friend_profile_custom_string_info_key": "Tag_Profile_Custom_Str",
"friend_profile_custom_string_info_value": "test3-lamar-value"
}],
"friend_profile_group_name_array": [],
"friend_profile_identifier": "98826",
"friend_profile_remark": "",
"friend_profile_user_profile": {
"user_profile_add_permission": 1,
"user_profile_birthday": 2000,
"user_profile_custom_string_array": [{
"user_profile_custom_string_info_key": "Tag_Profile_Custom_Str",
"user_profile_custom_string_info_value": "test3-lamar-value"
}],
"user_profile_face_url": "test1-www.google.com",
"user_profile_gender": 2,
"user_profile_identifier": "98826",
"user_profile_language": 1000,
"user_profile_level": 3000,
"user_profile_location": "shenzhen",
"user_profile_nick_name": "test change8888",
"user_profile_role": 4000,
"user_profile_self_signature": "1111111"
}
},
"friendship_friend_info_get_result_identifier": "98826",
"friendship_friend_info_get_result_relation_type": 0
}
]' // For the meaning of Json Key, please refer to [FriendInfoGetResult]
user_data:string
Return value details
name | type | description |
---|---|---|
TIMResult | TIMResult | Return value of calling API |
code | int | Result error code: Error Codes |
desc | string | The description of the error. |
json_param | string | Json string. Calling different API will get different Json strings. For the meaning of Json Key, please refer to [FriendInfoGetResult] |
user_data | string | User-defined data transfered by ImSDK without any processing |
Code example
using UnityEngine;
using UnityEngine.UI;
using com.tencent.im.unity.demo.types;
using com.tencent.imsdk.unity;
using com.tencent.imsdk.unity.types;
using com.tencent.imsdk.unity.enums;
using System;
using com.tencent.im.unity.demo.utils;
using EasyUI.Toast;
using System.Collections;
using System.Text;
using System.Collections.Generic;
public class FriendshipSearchFriends : MonoBehaviour
{
string[] Labels = new string[] { "KeywordLabel", "FriendSearchFieldLabel" };
public Text Header;
public InputField Input;
public Dropdown FriendSearchField;
public Text Result;
public Button Submit;
public Button Copy;
public int[] EnumFriendSearchField = (int[])Enum.GetValues(typeof(TIMFriendshipSearchFieldKey));
void Start()
{
foreach (string label in Labels)
{
GameObject.Find(label).GetComponent<Text>().text = Utils.t(label);
}
Header = GameObject.Find("HeaderText").GetComponent<Text>();
Input = GameObject.Find("InputField").GetComponent<InputField>();
FriendSearchField = GameObject.Find("FriendSearchField").GetComponent<Dropdown>();
foreach (string name in Enum.GetNames(typeof(TIMFriendshipSearchFieldKey)))
{
Dropdown.OptionData option = new Dropdown.OptionData();
option.text = name;
FriendSearchField.options.Add(option);
}
Result = GameObject.Find("ResultText").GetComponent<Text>();
Submit = GameObject.Find("Submit").GetComponent<Button>();
Copy = GameObject.Find("Copy").GetComponent<Button>();
Submit.onClick.AddListener(FriendshipSearchFriendsSDK);
Copy.GetComponentInChildren<Text>().text = Utils.t("Copy");
Copy.onClick.AddListener(CopyText);
if (CurrentSceneInfo.info != null)
{
Header.text = Utils.IsCn() ? CurrentSceneInfo.info.apiText + " " + CurrentSceneInfo.info.apiName : CurrentSceneInfo.info.apiName;
Submit.GetComponentInChildren<Text>().text = CurrentSceneInfo.info.apiName;
}
}
void FriendshipSearchFriendsSDK()
{
var param = new FriendSearchParam
{
friendship_search_param_keyword_list = new List<string>
{
Input.text
},
friendship_search_param_search_field_list = new List<TIMFriendshipSearchFieldKey>
{
(TIMFriendshipSearchFieldKey) EnumFriendSearchField[FriendSearchField.value]
}
};
TIMResult res = TencentIMSDK.FriendshipSearchFriends(param, Utils.addAsyncStringDataToScreen(GetResult));
Result.text = Utils.SynchronizeResult(res);
}
void GetResult(params object[] parameters)
{
Result.text += (string)parameters[0];
}
void CopyText()
{
Utils.Copy(Result.text);
}
void OnApplicationQuit()
{
TencentIMSDK.Uninit();
}
}