Python调用微软翻译接口

Python调用微软翻译接口,实现文字内容的自动翻译。

批量关键字翻译,批量内容的伪原创,有了这个接口都可以实现。python代码如下:

import json
import requests
import urllib
args = {
‘client_id’: ”,#your client id here
‘client_secret’: ”,#your azure secret here
‘scope’: ‘http://api.microsofttranslator.com’,
‘grant_type’: ‘client_credentials’
}
oauth_url = ‘https://datamarket.accesscontrol.windows.net/v2/OAuth2-13’
oauth_junk = json.loads(requests.post(oauth_url,data=urllib.urlencode(args)).content)
translation_args = {
‘text’: “hello”,
‘to’: ‘zh’,
‘from’: ‘en’
}
headers={‘Authorization’: ‘Bearer ‘+oauth_junk[‘access_token’]}
translation_url = ‘http://api.microsofttranslator.com/V2/Ajax.svc/Translate?’
translation_result = requests.get(translation_url+urllib.urlencode(translation_args),headers=headers)
print translation_result.content

需要安装python的requests模块,自己下载即可。broker mfxinstawowphoto.net

Leave a Comment