한국어를 중국어로 번역api
post /chinese
바디 json
{"content" : "안녕하세요~" }
https://developers.naver.com/apps/#/myapps/IrV0g7biQMVi5f1qm545/config
애플리케이션 - NAVER Developers
developers.naver.com

req_data = {'source' : 'ko','target':'zh-CN','text' : data['content'] }
header
headers = {'X-Naver-Client-Id' : Config.NAVER_CLIENT_ID,
'X-Naver-Client-Secret' : Config.NAVER_CLIENT_SECRET,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
api 호출
response = requests.post('https://openapi.naver.com/v1/papago/n2mt', req_data,headers=headers )
response값을 json화 시켜서
print 해보면
https://jsoneditoronline.org/#left=local.zacuxe&right=local.fuxivu
JSON Editor Online: JSON editor, JSON formatter, query JSON
You need to enable JavaScript to run this app. JSON Editor Online JSON Editor Online is a web-based tool to view, edit, format, repair, compare, query, transform, validate, and share your JSON data. About JSON Editor Online JSON Editor Online is a versatil
jsoneditoronline.org
message에 result에 translatedtext가 필요
result_text = response['message']['result']['translatedText']
최종
class NaverPapagoResource(Resource) :
def post(self) :
# {"content" : "안녕하세요~" }
data = request.get_json()
# 네이버 파파고 api 호출
req_data = {'source' : 'ko','target':'zh-CN','text' : data['content'] }
headers = {'X-Naver-Client-Id' : Config.NAVER_CLIENT_ID,
'X-Naver-Client-Secret' : Config.NAVER_CLIENT_SECRET,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
response = requests.post('https://openapi.naver.com/v1/papago/n2mt', req_data,headers=headers )
print(response.json())
response = response.json()
result_text = response['message']['result']['translatedText']
return{'result' : 'success' ,
'items' : result_text },200
'Api 개발 > flask' 카테고리의 다른 글
serverless 배부용 서버 배포 (0) | 2023.01.17 |
---|---|
lambda 실행 time out 해제 (0) | 2023.01.17 |
네이버 검색 api 활용 (0) | 2023.01.13 |
사진과 내용을 동시에 올리는 api (0) | 2023.01.13 |
s3에 저장된 이미지를 객체 탐지하는 API 만들기 (0) | 2023.01.12 |