Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8017109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:44:44+00:00 2026-06-04T20:44:44+00:00

I am trying to programatically perform a search on Microsoft Bing search engine. Here

  • 0

I am trying to programatically perform a search on Microsoft Bing search engine.

Here is my understanding:

  • There was a Bing Search API 2.0 , which will be replaced soon (1st Aug 2012)
  • The new API is known as Windows Azure Marketplace.
  • You use different URL for the two.

In the old API (Bing Search API 2.0), you specify a key (Application ID) in the URL, and such key will be used to authenticate the request. As long as you have the key as a parameter in the URL, you can obtain the results.

In the new API (Windows Azure Marketplace), you do NOT include the key (Account Key) in the URL. Instead, you put in a query URL, then the server will ask for your credentials. When using a browser, there will be a pop-up asking for a/c name and password. Instruction was to leave the account name blank and insert your key in the password field.

Okay, I have done all that and I can see a JSON-formatted results of my search on my browser page.

How do I do this programmatically in PHP? I tried searching for the documentation and sample code from Microsoft MSDN library, but I was either searching in the wrong place, or there are extremely limited resources in there.

Would anyone be able to tell me how do you do the “enter the key in the password field in the pop-up” part in PHP please?

Thanks alot in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:44:45+00:00Added an answer on June 4, 2026 at 8:44 pm

    Documentation for new services can get a bit interesting – especially in the rabbit-warren of MSDN. The most clear explanation I can find is on the Migration Guide from this Bing Search API page. Best of all the migration guide has a nice simple example in PHP towards the end.

    EDIT: Alright, the migration guide is a starting point, but it isn’t the best example. Here are two methods that work for me (no proxy, firewalls etc. interfering):

    Using file_get_contents

    Note: ‘allow_url_fopen‘ needs to be enabled for this to work. You can use ini_set (or change php.ini etc.) if it isn’t.

    if (isset($_POST['submit'])) 
    {
    
        // Replace this value with your account key
        $accountKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=';            
        $ServiceRootURL =  'https://api.datamarket.azure.com/Bing/Search/';                    
        $WebSearchURL = $ServiceRootURL . 'Web?$format=json&Query=';
    
        $cred = sprintf('Authorization: Basic %s', 
          base64_encode($accountKey . ":" . $accountKey) );
    
        $context = stream_context_create(array(
            'http' => array(
                'header'  => $cred
            )
        ));
    
        $request = $WebSearchURL . urlencode( '\'' . $_POST["searchText"] . '\'');
    
        $response = file_get_contents($request, 0, $context);
    
        $jsonobj = json_decode($response);
    
        echo('<ul ID="resultList">');
    
        foreach($jsonobj->d->results as $value)
        {                        
            echo('<li class="resultlistitem"><a href="' 
                    . $value->URL . '">'.$value->Title.'</a>');
        }
    
        echo("</ul>");
    }
    

    Using cURL

    If cURL is installed, which is normal these days:

    <?php
      $query = $_POST['searchText'];
    
      $accountKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
      $serviceRootURL =  'https://api.datamarket.azure.com/Bing/Search/';  
      $webSearchURL = $serviceRootURL . 'Web?$format=json&Query=';
    
      $request = $webSearchURL . "%27" . urlencode( "$query" ) . "%27";
    
      $process = curl_init($request);
      curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($process, CURLOPT_USERPWD,  "$accountKey:$accountKey");
      curl_setopt($process, CURLOPT_TIMEOUT, 30);
      curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
      $response = curl_exec($process);
      $response = json_decode($response);
    
      echo "<ol>";
      foreach( $response->d->results as $result ) {
        $url = $result->Url;
        $title = $result->Title;
    
        echo "<li><a href='$url'>$title</a></li>";
      }
      echo "</ol>";
    ?>
    

    [WTS] changed SearchWeb to Search.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying an example from M$ site regarding calling Windows Update programatically. 'http://msdn.microsoft.com/en-us/library/aa387102%28VS.85%29.aspx 'http://msdn.microsoft.com/en-us/library/aa386526%28v=vs.85%29.aspx
I'm trying to create programatically a custom view controller with subviews which center on
I am trying to add ImageView programatically inside a LinearLayout, which has vertical orientation.
I'm trying to use RMO to programmatically perform merge synchronization. I've basically copied the
I am trying to programatically unzip a zipped file. I have tried using the
I'm trying to programatically get a list of installed fonts in C or Python.
I am trying to programatically determine if a VOB is mounted in clearcase. Specifically,
I am trying to programatically build a list of files in a folder, with
I am trying to programatically validate a user login/pass using Spring Security, so I
I'm trying to programatically change the text of an edit control in a 'Save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.