//Para static string paraphrasing(string sentence, char numOfParas) { AdmAccessToken admToken; string urlTemplate = "http://api.microsofttranslator.com/v3/json/paraphrase?sentence={0}&language={1}&category={2}&maxParaphrases={3}"; string headerValue; //Get Client Id and Client Secret from //https://datamarket.azure.com/developer/applications/ AdmAuthentication admAuth = new AdmAuthentication( "61ac4bbd-ceea-4cd2-a33e-26ac7644f516", "I7kv+trhQqTDI9egay1fwTgXG0URzMnb4m4kURzov5k="); try { admToken = admAuth.GetAccessToken(); DateTime tokenReceived = DateTime.Now; // Create a header with the access_token //property of the returned token headerValue = "Bearer " + admToken.access_token; if ((DateTime.Now - tokenReceived).TotalSeconds > 600) { throw new Exception("Authentication token expired"); } else { string url = string.Format(urlTemplate, sentence, "en-us", "general", numOfParas); string paraphraseResult = GetParaphrases(url, headerValue); return(paraphraseResult); } } catch (Exception ex) { return(ex.Message); } }
//Para static string paraphrasing(string sentence, char numOfParas) { AdmAccessToken admToken; string urlTemplate = "http://api.microsofttranslator.com/v3/json/paraphrase?sentence={0}&language={1}&category={2}&maxParaphrases={3}"; string headerValue; //Get Client Id and Client Secret from //https://datamarket.azure.com/developer/applications/ AdmAuthentication admAuth = new AdmAuthentication( "61ac4bbd-ceea-4cd2-a33e-26ac7644f516", "I7kv+trhQqTDI9egay1fwTgXG0URzMnb4m4kURzov5k="); try { admToken = admAuth.GetAccessToken(); DateTime tokenReceived = DateTime.Now; // Create a header with the access_token //property of the returned token headerValue = "Bearer " + admToken.access_token; if ((DateTime.Now - tokenReceived).TotalSeconds > 600) { throw new Exception("Authentication token expired"); } else { string url = string.Format(urlTemplate, sentence, "en-us", "general", numOfParas); string paraphraseResult = GetParaphrases(url, headerValue); return paraphraseResult; } } catch (Exception ex) { return ex.Message; } }