getting the following.
HTTP/1.1 400 Bad Request Content-Length: 264 Content-Type: text/html; charset=utf-8 X-MS-Trans-Info: s=35641 Date: Wed, 25 Jun 2014 14:19:55 GMT <html><body><h1>TranslateApiException</h1><p>Method: Translate()</p><p>Message: The Azure Market Place Translator Subscription associated with the request credentials has zero balance.</p><code></code><p>message id=5641.V2_Rest.Translate.40BD29BC</p></body></html>
I am using the client id and secret from my application and I have a subscription marked active. my code is below.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace transalte
{
internal class Program
{
private static void Main(string[] args)
{
Token toke = Task.Run(async () =>
{
HttpClient cl = new HttpClient();
var token = new HttpRequestMessage();
Uri url = new Uri("https://datamarket.accesscontrol.windows.net/v2/OAuth2-13");
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("grant_type", "client_credentials");
dic.Add("client_id", "CLIENTID");
dic.Add("client_secret", "SECRET");
dic.Add("scope", "http://api.microsofttranslator.com");
var r2 = await cl.PostAsync(url, new FormUrlEncodedContent(dic));
var c = await r2.Content.ReadAsStringAsync();
Token o = JsonConvert.DeserializeObject<Token>(c);
return o;
}).ConfigureAwait(false).GetAwaiter().GetResult();
string text = Console.ReadLine();
while (text != "q")
{
Task.Run(async () =>
{
using (HttpClient cl = new HttpClient())
{
using (var r = new HttpRequestMessage())
{
r.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", toke.access_token);
r.RequestUri = new Uri("http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + text + "&to=fr");
var la = await cl.SendAsync(r);
var resp = XDocument.Parse(await la.Content.ReadAsStringAsync());
Console.WriteLine(resp.Root.Value);
}
}
}).ConfigureAwait(false);
text = Console.ReadLine();
}
}
private class Token
{
public string access_token { get; set; }
public string expires_in { get; set; }
public string scope { get; set; }
public string token_type { get; set; }
}
}
}