Bing API authorization does not work. The authentication type you specified is not supported. Only Basic and OAuth Supported

I recently received an email from Microsoft stating that the Bing API has migrated to the Windows Azure Marketplace. It seemed that the main difference between the new request was authentication.

After reading many forum posts, I found the following:

$accountKey = '#########';
$api =  'https://api.datamarket.azure.com/Bing/Search/Web?$format=json&$top=8&Query=';
$context = stream_context_create(array(
    'http' => array(
        'request_fulluri' => true,
        'header'  => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
    )
));
$request = $api.'%27'.$q.'%27&$skip='.$start;
$result = file_get_contents($request, 0, $context);

However, I still get the error message "The type of authorization you provided is not supported. Only Basic and OAuth are supported."

Does anyone know how I can fix this. I also tried cURL and it does not work. Thanks to everyone who can find me a solution.

+6
source share
4 answers

, URL- . . URL- :

$api = 'https://api.datamarket.azure.com/Data.ashx/Bing/Search/v1/Web?$format=json&$top=8&Query=';
$context = stream_context_create(array(
    'http' => array(
        'request_fulluri' => true,
        'header'  => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey)
    )
));
$q = 'test';
$request = $api.'%27'.$q.'%27';

echo file_get_contents($request, 0, $context);
+3

API , "XXXX". , cURL, "CURLOPT_SSL_VERIFYPEER" : (

$url = 'https://api.datamarket.azure.com/Bing/Search/Web?Query=%27xbox%27';
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD, "username:XXXX");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($process);

# Deliver
return $response;

# Have a great day!
curl_close($process);
+2

, - . , _ .

    $url = 'https://api.datamarket.azure.com/Data.ashx/Bing/MicrosoftTranslator/v1/Translate?Text=%27'.urlencode($text).'%27&To=%27' . $to . '%27&From=%27' . $from . '%27&$top=100&$format=json';

    $accountKey = 'APIKEY';
    $handle = curl_init ($url);
    if ($handle) {
        $curlOptArr = array(
            CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
            CURLOPT_USERPWD => $accountKey . ':' . $accountKey,
            CURLOPT_RETURNTRANSFER => TRUE

        );
        curl_setopt_array($handle, $curlOptArr);
        $response = curl_exec($handle);
        $data = json_decode($response,true);
        if (is_array($data)) {
            if (isset($data['d']['results'][0]['Text'])) {
                print $data['d']['results'][0]['Text'];
            } else {
                print false;
            }
        } else {
            print $text;
        }
        $errRet = curl_error($handle);
        curl_close($handle);
    }

This works for me when using cURL.

-1
source

All Articles