翻译API:变量文本翻译为空


bing translator API: variable text translated empty

我遇到了一个问题。我正在使用javascript和PHP。这段PHP代码运行(从大量的echo:D中可以看到),直到变量$curlResponse。从这个变量开始,以及后面的所有其他变量($xmlObj, $translatedStr, $translatedText)都是空的!有人能帮我吗?

<?php
try {
    $clientID       = "XXX";
    //Client Secret key of the application.
    $clientSecret = "XXX";
    //OAuth Url.
    $authUrl      = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13/";
    //Application Scope Url
    $scopeUrl     = "http://api.microsofttranslator.com";
    //Application grant type
    $grantType    = "client_credentials";
        // Create the AccessTokenAuthentication object.
        $authObj = new AccessTokenAuthentication();
        // Get the Access token.
        $accessToken = $authObj->getTokens($grantType, $scopeUrl, $clientID,           $clientSecret, $authUrl);
        // Create the authorization Header string.
        $authHeader = "Authorization: Bearer ". $accessToken;
        echo "<script type='text/javascript'>alert('$authHeader');</script>";
        // Set the parameters.
        // Sets source language. $fromLanguage = variable, langs[source][0] = name of textarea.
        $fromLanguage = $_COOKIE['cookie_source'];

        // Sets destination language. $toLanguage = variable, dest_lang = name of textarea.
        $toLanguage = $_COOKIE['cookie_dest'];
        // Sets text to translate. $inputStr = variable, source_text = content of thextarea.
        $inputStr = $_COOKIE['cookie_final'];
        echo "<script type='text/javascript'>alert('$inputStr');</script>";
        $contentType = 'text/plain';
        $category = 'general';
        // Variable that composes the string of parameters for the transaltion
        $paramst = "text=".urlencode($inputStr)."&to=".$toLanguage."&from=".$fromLanguage;
        echo "<script type='text/javascript'>alert('$paramst');</script>";

        // URL to translate the text
         $translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?$paramst";
        echo "<script type='text/javascript'>alert('$translateUrl');</script>";
        //Create the Translator Object.
        $translatorObj = new HTTPTranslator();

        //Get the curlResponse.
        $curlResponse = $translatorObj->curlRequest($translateUrl, $authHeader);
        echo "<script type='text/javascript'>alert('$curlResponse');</script>";
        //Interprets a string of XML into an object.
        $xmlObj = simplexml_load_string($curlResponse);
        foreach((array)$xmlObj[0] as $val) {
            $translatedStr = $val;
        }

        echo "<script type='text/javascript'>alert('$translatedStr');</script>";
        $translatedText = urlencode($translatedStr);
        echo "<script type='text/javascript'>alert('$translatedText');</script>";
        if (isset($inputStr)== true){
            if ($translatedStr==''){
            } else {
                echo "<script type='text/javascript'>alert('e piena');</script>";
            }
        }
} catch (Exception $e) {
    echo "Exception: ".$e->getMessage().PHP_EOL;
}
?>

请说明从哪里得到的类文件,为什么不使用这里提供的源代码,我相信它工作良好

<?php
/**
 * This file will retuen JSON response
 */
require_once('config.inc.php');
require_once('class/ServicesJSON.class.php');
require_once('class/MicrosoftTranslator.class.php');
$translator = new MicrosoftTranslator(ACCOUNT_KEY);
$text_to_translate = $_REQUEST['text'];
$to = $_REQUEST['to'];
$from = $_REQUEST['from'];
$translator->translate($from, $to, $text_to_translate);
echo $translator->response->jsonResponse;
?>