Detect Method

Use the Detect Method to identify the language of a selected piece of text.

Request URI

URI parameters
Parameter Description


Required. A string containing "Bearer" + " " + access token.


Required. A string representing the text from an unknown language. The size of the text must not exceed 10000 characters.

Return value
A string containing a two-character Language code for the given text.

Ff512396.alert_note(en-us,MSDN.10).gif Note

Bing App ID is deprecated and is no longer supported.   Please obtain an access token to use the Microsoft Translator API. For details, go here.


Obtain an Access Token on the server-side

public static AdmAccessToken GetAccessToken()
    AdmAccessToken admToken;
    string headerValue;
    //Get Client Id and Client Secret from
    AdmAuthentication admAuth = new AdmAuthentication("clientid", "clientsecret");

    admToken = admAuth.GetAccessToken();
    // Create a header with the access_token property of the returned token
    headerValue = "Bearer" + " " + HttpUtility.UrlEncode(admToken.access_token);

    return admToken;
Invoke the AJAX method on the client-side

<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        function detectLanguage() {

            var textToDetect = document.getElementById('<%= txtDetectLan.ClientID %>').value;
            if (textToDetect != "") {

                PageMethods.GetAccessToken(OnSucceeded, OnFailed);
        function OnSucceeded(result, usercontext, methodName) {
            var textToDetect = document.getElementById('<%= txtDetectLan.ClientID %>').value;
            if (textToDetect != "") {
                window.mycallback = function (response) {

                    document.getElementById('<%= lblLangDetect.ClientID %>').innerHTML = "The detected language is:" + response;
                var text = encodeURIComponent(textToDetect);
                var s = document.createElement("script");
                s.src = " " + encodeURIComponent(result.access_token) + "&text=" + text;


        function OnFailed(error, userContext, methodName) {
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
        <asp:Label ID="labelDetect" runat="server" Text="Enter Text to detect language"></asp:Label>
        <asp:TextBox ID="txtDetectLan" runat="server">
        <asp:Button ID="buttonDetetc" runat="server" Text="Detect language" OnClientClick="detectLanguage();return false;" />
        <br />
        <asp:Label ID="lblLangDetect" runat="server">
        <br />