문의 시, 디벨로퍼스 앱ID를 알려주세요.
- 친구 api와 피커, 메시지 api 사용을 위한 체크 리스트 ( 친구 api와 피커, 메시지 api 사용을 위한 체크 리스트 ) 먼저 확인해주세요.
- 메시지 API 권한 신청은 “디벨로퍼스>내 애플리케이션>앱 설정>앱 권한” 메뉴에서 신청 할 수 있습니다.
developers id : 1278795
AWS EC2 에서 IP 발급받아서 사용중인데요 http://3.36.172.252
파이썬으로 아래와 같이 함수를 만들었는데, response 값이 자꾸 401로 뜹니다.
별도 파일에 등록한 access_token은 문제 없는 것을 확인했습니다. (로컬컴퓨터에서는 잘 작동하거든요)
def send_kakao_message(self, message):
"""카카오톡으로 메시지를 전송합니다."""
if not self.access_token:
print("카카오톡 액세스 토큰이 설정되지 않았습니다.")
return False
url = "https://kapi.kakao.com/v2/api/talk/memo/default/send"
headers = {
"Authorization": f"Bearer {self.access_token}"
}
data = {
"template_object": json.dumps({
"object_type": "text",
"text": message,
"link": {
"web_url": "https://www.dhlottery.co.kr",
"mobile_web_url": "https://www.dhlottery.co.kr"
}
})
}
try:
response = requests.post(url, headers=headers, data=data)
if response.status_code == 200:
print("카카오톡 메시지 전송 성공!")
return True
else:
print(f"카카오톡 메시지 전송 실패: {response.status_code}")
return False
except Exception as e:
print(f"카카오톡 메시지 전송 중 오류: {e}")
return False