Answered Bing API working php+curl example??

  • Friday, February 01, 2013 8:37 AM
     
      Has Code

    After trying many of the php and curl based methods to access the Bing Api none of them work!! Can someone please give a very basic example, with php and curl.. Ive tried the code below not working, I get the error 'The request was not accepted by the data provider's service. The team is investigating the issue. We are sorry for the inconvenience'

    METHOD 1 --NOT WORKING!

    <?php 
    
    //replace with your own account key
    $accountKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_URL, 'https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%27Adelaide%27');
    $headers = array('header' => "Authorization: Basic " . base64_encode($accountKey . ":" . $accountKey));
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($ch);
    echo $response;
    
    curl_close($ch);
    
    ?>

    METHOD 2 - NOT WORKING - The authorization type you provided is not supported. Only Basic and OAuth are supported

    <?php 
    //I have my own key here
    $accountKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD,  base64_encode($accountKey . ":" . $accountKey));
    curl_setopt ($ch, CURLOPT_URL, 'https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%27Adelaide%27');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $file_contents = curl_exec($ch);
    echo $file_contents;
    curl_close($ch);
    
    ?>

    SO WHAT IS A WORKING SIMPLE EXAMPLE, i have tried many variations but no go.

    What is the correct way to pass the account key, with headers or with CURL like

    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

    I have already spent 3 days with nothing working. The strange thing is if you just paste the following

    https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%27Adelaide%27

    into your browser and and use your accountKey as the password, it works fine.. Surely how difficult could it be to do this with php..

    Please Help.. Thanks in advance

    SO..WHY IS THE FOLLOWING CODE NOT WORKING!!!!!!!!!!!!! again the error:

    The request was not accepted by the data provider's service. The team is investigating the issue. We are sorry for the inconvenience.

    <?php
    //I have my own key here 
    $accountKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD,  $accountKey.":".$accountKey);
    curl_setopt ($ch, CURLOPT_URL, 'https://api.datamarket.azure.com/Bing/Search/Web?$format=json&Query=%27Adelaide%27');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 30);
    $file_contents = curl_exec($ch);
    echo $file_contents;
    curl_close($ch);
    ?>

    Maybe someone can also show me how you can maybe also do this with curl binary from command line, i've tried all of that too and no go..




    • Edited by cooljaydude Friday, February 01, 2013 9:35 AM
    •  

All Replies