* guide : https://msdn.microsoft.com/en-us/library/hh454950.aspx
* 순서
1. azure marketplace 에 계정 생성.
2. my application --> register --> client_id, client_secret 확인 --> CREATE!
3. marketplace 에서 microsoft translator 검색
4. not available in my market 이라고 뜨면 my account 에서 내 지역을 확인해본다. worldwide(english) 로 설정해뒀었는데, korea 로 변경하니 선택이 가능해짐. ㅠ
5. 2M text 0$ per month 로 free 하게 사용 선택!
* 사용해보자
1. accessToken 얻기
- https://datamarket.accesscontrol.windows.net/v2/OAuth2-13
- post
- params
+ grant_type : client_credentials
+ client_id
+ client_secret
+ scope : http://api.microsofttranslator.com
- content-type : application/x-www-form-urlencoded
- response
{
token_type: "http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0"
access_token: "http%3a%2f%2fschemas.xmlsoap.org%2fws%2f2005%2f05%2fidentity%2fclaims%2fnameidentifier=xxxxxxxxxxx&http%3a%2f%2fschemas.microsoft.com%2faccesscontrolservice%2f2010%2f07%2fclaims%2fidentityprovider=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&Audience=http%3a%2f%2fapi.microsofttranslator.com&ExpiresOn=1433985543&Issuer=https%3a%2f%2fdatamarket.accesscontrol.windows.net%2f&HMACSHA256=xxxxxxxxxxx"
expires_in: "600"
scope: "http://api.microsofttranslator.com"
}
2. 위에서 획득한 access_token 으로 api 호출
- http://api.microsofttranslator.com/V2/Ajax.svc/Translate (편의상 ajax 인터페이스로 테스트해봄.)
- params
+ appId = "Bearer " + encodeURIComponent(access_token)
+ text : 번역할 텍스트
+ from : ko (한국어)
+ to : ja (일본어)
- http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=Bearer http%253a%252f%252fschemas.xmlsoap.org%252fws%252f2005%252f05%252fidentity%252fclaims%252fnameidentifier%3Dxxxxxxxxxxx%26http%253a%252f%252fschemas.microsoft.com%252faccesscontrolservice%252f2010%252f07%252fclaims%252fidentityprovider%3Dhttps%253a%252f%252fdatamarket.accesscontrol.windows.net%252f%26Audience%3Dhttp%253a%252f%252fapi.microsofttranslator.com%26ExpiresOn%3D1433986072%26Issuer%3Dhttps%253a%252f%252fdatamarket.accesscontrol.windows.net%252f%26HMACSHA256%3Dxxxxxxxxxxx%252f6CZfZKLuM%253d&text=환불여부&from=ko&to=ja
- response
"返金するかどうか"
- 위 가이드 문서에 보면 ajax, http, soap 인터페이스에 대한 정의와 예제가 있다.
* 생각나는게 딱히 없어서 '밥 먹었니?' 로 구글 번역기로 비교
+ microsoft : Bob ate?
+ google : You eaten rice?
- bob 이라니... ㅠ
- 그래도 영어를 from으로 번역하는 건 품질이 괜찮겠지?
google translator api 는 무료로 지원하지 않는다. 다만, google translator 페이지의 요청을 따서 api 비슷하게 사용을 할 수는 있으나 그렇게 사용해도 문제가 없을지는 모르겠다.
'dev' 카테고리의 다른 글
뿌띠를 탭으로 관리할 수 있는 MTPuTTY (0) | 2015.07.02 |
---|---|
ie 버전별 테스트 (1) | 2015.06.17 |
thymeleaf 가 먹는 것임? (0) | 2015.05.20 |
javascript chart library (0) | 2015.05.19 |
루비 시작하기 - 설치 (0) | 2014.10.07 |