0

I've been using BING TRANSLATE API a couple of months ago and everything was working perfect.

Now I needed to open the old files and translate something , but it seems it's not working anymore.

Tried to do some search on BING website but it's very messed up. Also I did search on Google but there are so many outdated articles and I dont know which to believe.

Here is my previous code that worked perfectly.

I signed up for a new API key today, but I think the new API key is in base64_encode format. I tried decoding it and it still doesn't work. Of course I tried without decoding it.

Can anybody help with some guidance ?

Error:

{"SearchResponse":{"Version":"2.2","Query":{"SearchTerms":"fish"},"Errors":[{"Code":1002,"Message":"Parameter has invalid value.","Parameter":"SearchRequest.AppId","Value":"ccTq4vytm9Kh/MC8ux57OSvlU9 lqDkeiJkXM3L4jVk=","HelpUrl":"http://msdn.microsoft.com/en-us/library/dd251042.aspx"}]}}

My code

     define('BING_API','KEY_HERE_AAAAAAAAA');
function loadData($url, $ref = false) {
            $chImg = curl_init($url);
            curl_setopt($chImg, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($chImg, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0");
            if ($ref) {
                curl_setopt($chImg, CURLOPT_REFERER, $ref);
            }
            $curl_scraped_data = curl_exec($chImg);
            curl_close($chImg);
            return $curl_scraped_data;
        }

        function translate($text, $from = 'en', $to = 'fr') {
            $data = loadData('http://api.bing.net/json.aspx?AppId=' . BING_API . '&Sources=Translation&Version=2.2&Translation.SourceLanguage=' . $from . '&Translation.TargetLanguage=' . $to . '&Query=' . urlencode($text));
            $translated = json_decode($data);
            if (sizeof($translated) > 0) {
                if (isset($translated->SearchResponse->Translation->Results[0]->TranslatedTerm)) {
                    return $translated->SearchResponse->Translation->Results[0]->TranslatedTerm;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    echo translate('fish','en','fr');
NVG
  • 3,248
  • 10
  • 40
  • 60

2 Answers2

0

AFAIK, Bing Translator API was discontinued at some point, though I can't find a press release now. It was using the Microsoft Translator API behind the scenes.

Microsoft Translator API is now offered via Azure Marketplace. There is limited free access available.

Examples / code can be found here.

HTH.

Massimiliano
  • 16,770
  • 10
  • 69
  • 112
0

The API is still available -- it just moved to Windows Azure Marketplace.

There is a 2 million characters per month free option available.

PHP Sample here: http://blogs.msdn.com/b/translation/p/phptranslator.aspx

You can see how to get credentials for it here: http://blogs.msdn.com/b/translation/p/gettingstarted1.aspx

Laurence Moroney
  • 1,263
  • 8
  • 20