Using Microsoft Translator API with Windows Store App HTML 5 & Javascript

180px-MS-Translator-logo

is a translation portal by Microsoft as part of Bing services that can provide a machine-translation of texts or entire web pages. Microsoft Translator also provides a set of web service APIs (that can be called via an HTTP REST service, an AJAX callable service, or a SOAP service) for developers who wish to use Microsoft Translator in their applications.

In this article we will develop a Windows Store application that uses the AJAX callable service of Microsoft Translator to translate text between languages.

First you have subscribe to the Microsoft Translator API on windows azure from here. Follow this link will help you to subscribe. Then register your application on Azure Data Market to get the clientId and clientSecret that we will use to obtain the access token.
The access token is passed with each API call and is used to authenticate your access to the Microsoft Translator API. You must obtain an access token to use the Microsoft Translator API.

NOTE:  Bing AppID mechanism is deprecated and is no longer supported. As mentioned above, you must obtain an access token to use the Microsoft Translator API. The access token is more secure and more flexible.

Now we will create a Windows RunTime component (WinRT Component) project that will have two classes we will use to obtain our access token .

The first class is AdmAccessToken that will have Token Request Output Properties :


using System.Runtime.Serialization;

namespace MicrosoftTranslatorRT
{
  public sealed class AdmAccessToken
  {
    [DataMember]
    public string access_token { get; set; }
    [DataMember]
    public string token_type { get; set; }
    [DataMember]
    public string expires_in { get; set; }
    [DataMember]
    public string scope { get; set; }
  }
}

Continue reading

Advertisements