1

I've read this post: Bing search API and Azure

And I used the following code to mimic it:

<?php            
if (isset($_GET['bingquery'])){
    // Replace this value with your account key
    $accountKey = '***myaccountkey***';

    $WebSearchURL = 'https://api.datamarket.azure.com/Bing/Search/v1/' + 'News?$format=json&Query=';

    $cred = sprintf('Authorization: Basic %s', base64_encode($accountKey . ":" . $accountKey) );

    $context = stream_context_create(array(
        'http' => array(
            'header'  => $cred
        )
    ));

    $request = $WebSearchURL . urlencode( '\'' . $_GET["bingquery"] . '\'');

    $response = file_get_contents($request, 0, $context);

    echo $response;

} 
?>

My AJAX call is :

var bingquery = "bingquery=" + $('#query').val();

    $.ajax({
        url: "bingsearch.php",
        method: "get",
        dataType: "json",
        data: bingquery,
        success: function(jsondata){
            console.log(jsondata); 
        }
        });

However, I still can't get back the JSON format data from Bing Search, any suggestions? Thank you so much for your help!

Community
  • 1
  • 1
Paul
  • 119
  • 1
  • 9

1 Answers1

1

If I understood properly you are trying to make some what like proxy for your call.. but you have not set your HTTP header fields properly as of like your php file receives from api.datamarket.azure.com, so you need to set those please see this answer and set HTTP headers properly and also make your ajax call as mentioned here

Community
  • 1
  • 1
Shubham Takode
  • 457
  • 6
  • 19