안녕하세요
친구에게 메시지 보내기 기능에 대해서 도움을 얻고자합니다.
개발프로그램 C#
앱id : 821750
private void Btn_DefaultSendMessage_Click(object sender, EventArgs e)
{
Console.WriteLine(“커스텀 메시지 보내기 버튼”);
JObject SendJson = new JObject();
JObject LinkJson = new JObject();
LinkJson.Add("web_url", "https://developers.kakao.com");
LinkJson.Add("mobile_web_url", "https://developers.kakao.com");
SendJson.Add("object_type", "text");
SendJson.Add("text", "안녕하세요~.\n\n");
SendJson.Add("link", LinkJson);
SendJson.Add("button_title", "안녕");
Console.WriteLine(SendJson);
kakaoManager.KakaoDefaultSendMessage(SendJson);
}
– 출력 로그
커스텀 메시지 보내기 버튼
{
“object_type”: “text”,
“text”: “안녕하세요~.\n\n”,
“link”: {
“web_url”: “https://developers.kakao.com”,
“mobile_web_url”: “https://developers.kakao.com”
},
“button_title”: “안녕”
}
<추가 정보
KakaoHostApiUrl = https://kapi.kakao.com
KakaoUserDataUrl = “/v1/api/talk/friends”;
KakaoDefaultMessageUrl = “/v1/api/talk/friends/message/default/send”;
KakaoLogInUrl = “https://kauth.kakao.com/oauth/authorize?client_id=” + KakaoRestApiKey + “&redirect_uri=” +
KakaoRedirectUrl + “&response_type=code&scope=talk_message,friends”;
public void KakaoDefaultSendMessage(JObject sendMessageObject)
{
var client = new RestClient(kakaoApiEndPoint.KakaoHostApiUrl);
var request = new RestRequest(kakaoApiEndPoint.KakaoUserDataUrl, Method.GET);
request.AddHeader(“Authorization”, "bearer " + kakaoData.accessToken);
var restResponse = client.Execute(request);
var json = JObject.Parse(restResponse.Content);
var friends_list = json.GetValue("elements");
Console.WriteLine(friends_list.ToString());
Console.WriteLine(json["elements"][0]["uuid"].ToString());
var friend_id = friends_list[0]["uuid"];
var request2 = new RestRequest(kakaoApiEndPoint.KakaoDefaultMessageUrl, Method.POST);
request2.AddHeader("Authorization", "bearer " + kakaoData.accessToken);
request2.AddParameter("receiver_uuid", json["elements"][0]["uuid"].ToString());
request2.AddParameter("template_object", sendMessageObject);
if (client.Execute(request2).IsSuccessful)
{
Console.WriteLine("메시지 보내기 성공");
}
else
{
Console.WriteLine("메시지 보내기 실패");
}
}
– 출력 로그
[
{
“profile_nickname”: “비공개로할게요”,
“profile_thumbnail_image”: “https://p.kakaocdn.net/th/talkp/wns3VNzblQ/x1kgT5OsAB42DbrckggtA0/jbinsl_110x110_c.jpg”,
“allowed_msg”: true,
“id”: 2519784632,
“uuid”: “비공개로할게요”,
“favorite”: false
}
]
메시지 보내기 실패
uuid도 정상적으로 들고왔는데요
왜 친구에게 보내지지 않는지 모르겠습니다. 도움요청드려요.