Max, Justin,
Just for information, I have successfully created a local php-webservice that can be called through jQuery, passes the query to the Bing api and returns the json object.
It is not thaaaat fast (bit frustrating) but at least it works. If there is any possibility to use OAuth directly from jQuery I'm also very interested! I had understood it in the way Justin described, at first call a "token service", then send the token
together with the query to the Bing Api. But isn't that even slower to call two webservices?
Here my code for jquery and the local php webservice:
jQuery:
var wssearchtermhost = '/pathtolocalwebservice/wsbingapi.php';
function search() {
// Define query and pass to webservice
var wssearchtermparam = 'searchstr='+encodeURIComponent($('#searchbox').val());
$.getJSON(wssearchtermhost, wssearchtermparam, function (data) {showresponse(data);});
}
// Show search results
function showresponse(data){
//show json results through functions...
}
php webservice "wsbingapi.php", security functions excluded:
<?php
$searchstr = $_GET["searchstr"]);
$searchstr = str_replace(" ","%20",$searchstr); //workaround to pass spaces
//Bing Api Call
$accountKey = 'your application key';
$rooturl = 'https://api.datamarket.azure.com/Bing/SearchWeb/Web?';
$searchstr = 'Query=%27' . $searchstr . '%27';
$market = '&Market=%27en-US%27';
$adult = '&Adult=%27Moderate%27';
$options = '&Options=%27EnableHighlighting%27';
$websearchoptions = '&WebSearchOptions=%27DisableQueryAlterations%27';
$top = '&$top=10';
$skip = '&$skip=0';
$format = '&$format=JSON';
$parameters = $searchstr . $market . $adult . $options . $websearchoptions . $top . $skip . $format;
$ServiceRootURL = $rooturl . $parameters;
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("ignored:".$accountKey)
)));
$jsonresponse = file_get_contents($ServiceRootURL,0,$context);
echo $jsonresponse;
?>
Hope this helps :-)
Thank you and regards
Yukiko