I know this question is a few months old, but since I was dealing with this today I thought I would share my working code. Here's a simple example of how to use the Translate Method in the Microsoft Translator V2 API using your primary account key and basic authentication. You can obtain your primary account key here.
// Prepare variables
$text = urlencode('Hello world.');
$from = 'en';
$to = 'es';
// Prepare cURL command
$key = 'YOUR_PRIMARY_ACCOUNT_KEY';
$ch = curl_init('https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text=%27'.$text.'%27&From=%27'.$from.'%27&To=%27'.$to.'%27');
curl_setopt($ch, CURLOPT_USERPWD, $key.':'.$key);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Parse the XML response
$result = curl_exec($ch);
$result = explode('<d:Text m:type="Edm.String">', $result);
$result = explode('</d:Text>', $result[1]);
$result = $result[0];
echo $result;
This should return:
Hola mundo.
For more information on the GET
parameters, see the MSDN documentation.