user1922485
user1922485

Reputation: 41

Bing translator HTTP API throws bad request error, how to solve this?

Whenever I call Bing Translation API [HTTP] to translate some text, first time it works fine, and second time onwards it gives me 'bad request' [status code 400] error. If I wait for 10 or so minutes and then try again, then first request is successful, but second one onwards same story. I have a free account [2million chars translation] with Bing Translation APIs, are there any other limitations calling this API?

Thanks, Madhu

Answer: hi, i missed to subscribing to Microsoft Translator DATA set subscription. Once i get the same, then things have solved. i.e; once i have signed up for https://datamarket.azure.com/dataset/bing/microsofttranslator then things are working.

i was generating the access_token correctly, so that is not an issue. thanks, madhu

Upvotes: 3

Views: 2258

Answers (2)

richardtallent
richardtallent

Reputation: 35363

As a note to anyone else having problems, I figured out that the service only allows the token to be used once when using the free subscription. You have to have a paid subscription to call the Translate service more than once with each token. This limitation is, of course, undocumented.

I don't know if you can simply keep getting new tokens -- I suspect not.

And regardless of subscription, the tokens do expire every 10 minutes, so ensure you track when you receive a token and get a new one if needed, e.g. (not thread-safe):

private string _headerValue;
private DateTime _headerValueCreated = DateTime.MinValue;
public string headerValue {
    get {
        if(_headerValueCreated < DateTime.Now.AddMinutes(-9)) {
            var admAuth = new AdmAuthentication("myclientid", "mysecret");
            _headerValue = "Bearer " + admAuth.GetAccessToken();
            _headerValueCreated = DateTime.Now;
        }
        return _headerValue;
    }
}

Upvotes: 1

user1922485
user1922485

Reputation: 41

i missed to subscribing to Microsoft Translator DATA set subscription. Once i get the same, then things have solved. i.e; once i have signed up for https://datamarket.azure.com/dataset/bing/microsofttranslator then things are working.

i was thanks, madhu

Upvotes: 1

Related Questions