【问题标题】:Cannot connect to Bing Translator API无法连接到必应翻译 API
【发布时间】:2012-09-04 16:50:08
【问题描述】:

我有两个问题:

  1. 我不能不使用 Ruby 发布到 MS 的服务器。

  2. 我无法从 MS 的服务器获取结果。

以下是详细信息。

这是我的 ruby​​ 代码:(xxxxxx 是我的 client_secret)

require "net/http"

base_url = URI("https://datamarket.accesscontrol.windows.net/v2/OAuth2-13")
params = {:client_id => :woki,
          :client_secret => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
          :scope => "http://api.microsofttranslator.com",
          :grant_type => "client_credentials"}

res = Net::HTTP.post_form(base_url, {})

File.open("token", "w").write res.body

我希望使用此代码来获取我的访问令牌。

但是,每次发生错误时:

rescue in rbuf_fill': Timeout::Error (Timeout::Error)

所以,我改为使用 bash 命令 curl 发布,并返回响应:

{"token_type":"http://schemas.xmlsoap.org/ws/2009/11/swt-token-profile-1.0","access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","expires_in":"599","scope":"http://api.microsofttranslator.com"}

然后,我想用我的访问令牌将一个英文单词翻译成中文,但还是失败了。以下是我的代码:

#!/bin/bash

clear

curl -H "Authorization: Bearer xxxxx" -d "appId&text=apple&to=zh-CHS&from=en&maxTranslations=10" http://api.microsofttranslator.com/V2/Http.svc/GetTranslations

其中 xxxxx 是直接从上面的访问令牌复制而来的,如“http%3a%2f%2f”之类的内容。

根据http://msdn.microsoft.com/en-us/library/ff512417。我觉得没有错。

但是,我只得到

Error Status Code: 'InternalServerError'

Details: The server encountered an error processing the request. Please see the server logs for more details.

谁能告诉我问题出在哪里?

【问题讨论】:

    标签: api bing


    【解决方案1】:

    尝试重新排序您的参数 - 我看到您在 'from' 之前有 'to'。

    还可以尝试去掉“maxTranslations”参数。

    【讨论】:

      猜你喜欢
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      相关资源
      最近更新 更多