Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- $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;
- // 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;
- // URL to translate the text
- $translateUrl = "http://api.microsofttranslator.com/v2/Http.svc/Translate?$paramst";
- //Create the Translator Object.
- $translatorObj = new HTTPTranslator();
- //Get the curlResponse.
- $curlResponse = $translatorObj -> curlRequest($translateUrl, $authHeader);
- //Interprets a string of XML into an object.
- $xmlObj = simplexml_load_string($curlResponse);
- foreach((array)$xmlObj[0] as $val)
- {
- $translatedStr = $val;
- }
- $scrivi=utf8_decode($translatedStr);
- $translatedText = urlencode($translatedStr);
- $scrivi2=utf8_decode($translatedText);
- if (isset($inputStr)== true){
- echo "<script type='text/javascript'>alert('e piena');</script>";
- echo "<script type='text/javascript'>alert(.$translatedText);</script>";
- echo "<script type='text/javascript'>alert('.$translatedText');</script>";
- echo "<script type='text/javascript'>alert('.$translatedStr');</script>";
- echo "<script type='text/javascript'>alert(.$translatedStr);</script>";
- }
- }
- catch (Exception $e)
- {
- echo "Exception: ".$e->getMessage().PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement