Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
DetectArray Method

DetectArray Method

Use the DetectArray Method to identify the language of an array of strings all at once. Performs independent detection of each individual array element and returns a result for each element of the array.

Request URI

URI parameters
Parameter Description


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


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

Return value
A string array containing a two-character Language codes for each row of the input array.

Ff512397.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 https://datamarket.azure.com/developer/applications/
    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="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript">
        var texts = "[\"les erreurs sont parfois amusants.\", \"you can try to enter a longer phrase.\", \"Questo un testo italiano.\"]";

        function detectArray() {
            PageMethods.GetAccessToken(OnSucceeded, OnFailed);
        function OnSucceeded(result, usercontext, methodName) {

            window.mycallback = function (response) {
                var array = response;
                var detectedLanguages = "";
                for (var i = 0; i < array.length; i++) {
                    detectedLanguages = detectedLanguages + array[i] + "\n";
            var s = document.createElement("script");
            s.src = "http://api.microsofttranslator.com/V2/Ajax.svc/DetectArray?oncomplete=mycallback&appId=Bearer " + encodeURIComponent(result.access_token) + "&texts=" + texts;
        function OnFailed(error, userContext, methodName) {
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
        <asp:Button ID="buttonDetectArray" runat="server" Text="Detect array" OnClientClick="detectArray();return false;" />
© 2015 Microsoft