Incorporating Advertisements into Results

Bing API provides you with the ability to incorporate advertisements into your search results. To take advantage of this ability, perform the procedure at Monetize your search application. Creating a request to the Ad SourceType is much the same as creating a request to any Bing API SourceType, although there are a number of additional required parameters. These parameters are identified in Table 2.

Table 2: Ad SourceType Additional Required Parameters

Parameter Description

Ad.AdUnitId

Your AdCenter Unit ID

Ad.PropertyId

Your AdCenter Property ID

Ad.Pagenumber

The page number requested

Figure 4 shows results returned by a query to the Ad SourceType.

<?xml version="1.0" encoding="utf-8" ?> 
  <?pageview_candidate ?> 
- <SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.0">
- <Query>
  <SearchTerms>word powerpoint</SearchTerms> 
  </Query>
- <ads:Ad xmlns:ads="http://schemas.microsoft.com/LiveSearch/2008/04/XML/ads">
  <ads:Total>2</ads:Total> 
  <ads:PageNumber>0</ads:PageNumber> 
  <ads:AdApiVersion>1.0</ads:AdApiVersion> 
- <ads:Results>
- <ads:AdResult>
  <ads:Rank>1</ads:Rank> 
  <ads:Position>mainline</ads:Position> 
  <ads:Title>Sample Word 2007 Ad</ads:Title> 
  <ads:Description>Spend More Time Writing & Less Time Formatting with Word 2007.</ads:Description> 
  <ads:DisplayUrl>Microsoft.com/Office2007</ads:DisplayUrl> 
  <ads:AdLinkUrl>http://0.r.msn.com/?ld=2vj0c1Ca9KZ/KmiuYWlpfXcdGq+8uSk+BPAdEDywJtTYD3Cy8hy03njO7A4tgBWCFXszGFyPxq3cw0CyeJV1TL08GAvx4g865GqsBul8R3W2uBh6ZQ4k2k91E9jwnSZnfguoNH81sEt35A0m58e/OiP7zMaxNd/amhu6aIzQhYWf2lVQccf4Wx+HA+ykFoZmmZqMCV+iwE/RJXOx0OHGUOsmaF9FK1c7vwSE9HmMj9r0yHZn8+DZIL</ads:AdLinkUrl> 
  </ads:AdResult>
+ <ads:AdResult>
  </ads:Results>
  </ads:Ad>
  </SearchResponse>

Figure 4: Bing API Ad SourceType Response

As Figure 4 shows, Ad SourceType result sets are shaped exactly the same as other SourceTypes, with SearchResponse followed by the Ad element, and the Ad element having a number of AdResult elements. The data inside of AdResults can be used to create advertisements on your page; when a user clicks on that ad, your account at AdCenter is incremented.

Note

If you are going to use the Ad SourceType, you must also send the search client IP address in a special custom HTTP header as well as the Client user agent. Specifically, with each search request you send a special custom HTTP header: “search-client-ip”. The value of this header will be the IP address of the machine sending the request. (That is, the end user accessing your web site). You will also need to send the user agent information. (HTTP Header webRequest.Headers.Add("search-client-ip", "1.2.3.4");   User Agent request.UserAgent =”Your user agent”;)