Search the Community
Showing results for tags 'bing'.
-
Sample json query : https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%27Xbox%27 . If you click on the link you are prompted for a username and password. both fields just require you to insert your Bing API. How can I send the password with the query attached? I'm using cURL to send the query. I have tried using the normal method outlined by bing to receive the search results but it doesn't seem to work for me.
-
I'm just trying to retrieve results using bing API. All I have done so far is copy the example for the bing user manual. https://skydrive.live.com/view.aspx?resid=9C9479871FBFA822%21112&app=Word&authkey=%21ANNnJQREB0kDC04 but I'm getting an error with the scope of the variable. The variable in question is $context Warning: file_get_contents() [function.file-get-contents]: SSL: fatal protocol error in /home/msc2012/12254822/public_html/MetaSearchV1/bing_basic.php on line 35 Service Operation <?php $acctKey = 'xPx9I4rWqBBFRGO4+5aZai7x/KrqSMuM/jLIchClJ6I'; $rootUri = 'https://api.datamarket.azure.com/Bing/Search'; $contents = file_get_contents('index.html'); //contents therefore has basic in it as words? if ($_POST['query']) { $query = urlencode("'{$_POST['query']}'"); $serviceOp = $_POST['service_op']; $requestUri = "$rootUri/$serviceOp?\$format=json&Query=$query"; // Encode the credentials and create the stream context. $auth = base64_encode("$acctKey:$acctKey"); $data = array( 'http' => array( 'request_fulluri' => true, // ignore_errors can help debug – remove for production. This option added in PHP 5.2.10 'ignore_errors' => true, 'header' => "Authorization: Basic $auth") ); $context = stream_context_create($data); // Get the response from Bing. $response = file_get_contents($requestUri, 0, $conext); $jsonObj = json_decode($response); $resultStr = ''; foreach($jsonObj->d->results as $value) { switch ($value->__metadata->type) { case 'WebResult': $resultStr .= "<a href=\"{$value->Url}\">{$value->Title}</a><p>{$value->Description}</p>"; break; case 'ImageResult': $resultStr .= "<h4>{$value->Title} ({$value->Width}x{$value->Height}) " . "{$value->FileSize} bytes)</h4>" . "<a href=\"{$value->MediaUrl}\">" . "<img src=\"{$value->Thumbnail->MediaUrl}\"></a><br />"; break; } } $contents = str_replace('{RESULTS}', $resultStr, $contents); } echo $contents; ?>