I have two problem:
I cannot not post to MS's server in Ruby.
I cannot get result from MS's server.
Following is the details.
Here is my ruby code:(xxxxxx is my 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
I hopt to use this code to get my access token.
However, every time an error occurs:
rescue in rbuf_fill': Timeout::Error (Timeout::Error)
So, instead, I use bash command curl to post, and a response is returned:
{"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"}
Then, I want to use my access token to translate an English word into Chinese, but still failed. Following is my code:
#!/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
where xxxxx is directly copied from access token above, with something like "http%3a%2f%2f" as is.
According to http://msdn.microsoft.com/en-us/library/ff512417. I think there is nothing wrong.
However, I only get
Error Status Code: 'InternalServerError'
Details: The server encountered an error processing the request. Please see the server logs for more details.
Who can tell me where is the problem?