@
feiyuanqiu 多谢!明白了这个构造。
@
ljbha007 很感激这么详细的说明。我是用 python 来构造这个的。所以就想知道 PHP 这个实现跟我的到底哪儿不一样。不知你是否也懂 python ,若懂,也请看看我这段代码到底怎么回事,总是拿不回 token 的 json 值。写成以下这样,总是得到 400 bad request 。
class Microsoft_translator_api ():
"""translate text only"""
def __init__(self, text ):
self.text = text
self.request_url = "
datamarket.accesscontrol.windows.net/v2/OAuth2-13"
self.client_id = "我的应用名"
self.client_secret = "我的密钥"
self.grant_type = "client_credentials"
self.scope = "
http://api.microsofttranslator.com"
def get_token (self ):
params = urllib.urlencode ({'@grant_type': self.grant_type, '@scope': self.scope, '@client_id': self.client_id, '@client_secret': self.client_secret})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
request_token = httplib.HTTPConnection (self.request_url )
request_token.request ("POST", "", params, headers )
response = request_token.getresponse ()
print response.status, response.reason
token = response.read ()
#print token
request_token.close ()
return (token )