Live Services Synchronizing Life
Microsoft Live Search 2.0
Agenda • Why use Live Search 2.0? • Benefits • Where do you start?
Live Services Synchronizing Life
Why Live Search 2.0? • Power of Live Search • Flexible ad serving • New content types – Increase traffic – Increase customer engagement
• Analysis Tools – Provide business intelligence – Customer insights
Live Services Synchronizing Life
Benefits
Live Services Synchronizing Life
• Understand keyword performance data • Increase reach and relevance – Customizable search
• Monetize your site with ads • Access to: – News – Weather – Maps – Spelling – Instant answers
• Silverlight support
Programming Interfaces
Live Services Synchronizing Life
• HTTP – XML – JSON – Query parameters (AppID, query, sources)
• SOAP • RSS
Live Search Sources
Live Services Synchronizing Life
Source
Description
Web
Searches for Web content
Image
Searches for images on the web
News
Searches news stories
Instantanswer
Searches Microsoft Encarta online
Spell
Searches Microsoft Encarta dictionary Searches phonebook entries
Phonebook relatedsearch
Returns the query strings most similar to yours
Getting an API key • Go to http://search.live.com/ developers • Sign in with your Windows Live ID • Create a new AppID
Live Services Synchronizing Life
Live Services Synchronizing Life
Using HTTP
8
Typical HTTP Request
Live Services Synchronizing Life
http://api.search.live.net/xml.aspx? Appid=<AppID>&query=sushi&source s=web+image+news • Specify XML or JSON • Use your AppID • Pass in the query text • Specify the sources to search That’s it!
Demo
Live Services Synchronizing Life
Typical HTTP Requests
Using XML
Live Services Synchronizing Life
Paging
Live Services Synchronizing Life
• Query string parameters – Offset – Count Prefix both with the source
• Example: – http://api.search.live.net/xml.aspx? Appid=C8AA0270C8F5940FA2AA96C1048 F401ED4DA0494&query=sushi&sources=w eb +image&web.count=10&web.offset=50&im age.count=50&image.offset=100
XML Results
Live Services Synchronizing Life
Live Services Synchronizing Life
Using .NET
14
XML API from .NET
Live Services Synchronizing Life
string url = "http://api.search.live.net/xml.aspx? Appid={0}&sources={1}&query={2}"; string completeUri = String.Format(url, API_KEY, "image", "sushi"); HttpWebRequest webRequest = null; webRequest = (HttpWebRequest)WebRequest.Create(completeUri); HttpWebResponse webResponse = null; webResponse = (HttpWebResponse)webRequest.GetResponse();
Processing XML API image
Live Services Synchronizing Life
XDocument data = XDocument.Load(xmlReader); IEnumerable<XNode> nodes = null; nodes = data.Descendants(XName.Get("Results", IMAGE_NS)).Nodes(); if (nodes.Count() > 0) {
var results = from uris in nodes
select new LiveSearchResultImage
{
URI =
((XElement)uris).Element(XName.Get("Url", IMAGE_NS)).Value,
Title =
((XElement)uris).Element(XName.Get("Title", IMAGE_NS)).Value,
ThumbnailURI =
((XElement)uris).Element(XName.Get("Thumbnail",
IMAGE_NS)).Value,
};
return results;
JSON Results
Live Services Synchronizing Life
JSON serialized response: "SearchResponse":{ "Version":"2.0","Query":{ "SearchTerms":"sushi"},"Web":{ "Total":15000000,"Offset": 0,"Results":[ { "Title":"Sushi - Wikipedia, the free encyclopedia","Description":"In Japanese cuisine, sushi (!!, !, !, sushi?) is vinegared rice, usually topped with other ingredients, including fish (cooked or uncooked) and vegetables.","Url":"http:\/\/en.wikipedia.org\/wiki\/ Sushi","DisplayUrl ":"http:\/\/en.wikipedia.org\/wiki\/ Sushi","DateTime":"2008-0609T06:42:34Z"}]}} /* pageview_candidate */}
Demo
Live Services Synchronizing Life
JSON Query
18
Live Services Synchronizing Life
Live Search 2.0 SOAP APIs
.NET code using SOAP
Live Services Synchronizing Life
LiveSearchPortTypeClient soapClient = new LiveSearchPortTypeClient(); SearchRequest request = new SearchRequest(); request.AppId = API_KEY; request.Sources = new SourceType[] { SourceType.Image }; request.Query = query; SearchResponse response = soapClient.Search(request); if (response.Image != null && response.Image.Results.Count() > 0) {
var results = from uris in response.Image.Results
select new LiveSearchResultImage
{
URI = uris.Url,
Title = uris.Title,
ThumbnailURI = uris.Thumbnail.Url,
};
return results;
Demo
Live Services Synchronizing Life
ASP.NET Demo
21
Live Services Synchronizing Life
Silverlight
Silverlight
Live Services Synchronizing Life
• Create rich Search apps • Live Search 2.0 publishes a crossdomain.xml policy file – http://api.search.live.net/crossdomain.xml – Allows Search 2.0 API from Silverlight
• APIs are the same as .NET – HTTP XML or SOAP
• Also has a JSON parsing object model • APIs are asynchronous
Silverlight Sample Setup callback and make query WebClient wc = new WebClient(); wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted); item.CurrentQuery = p; item.Uri = new Uri(String.Format(_baseURI, API_KEY, "image", "sushi")); wc.OpenReadAsync(item.Uri, item); WebClient callback void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {
Stream streamResult = e.Result;
XDocument xd = XDocument.Load(XmlReader.Create(streamResult));
// use the Xdocument }
Live Services Synchronizing Life
Demo
Live Services Synchronizing Life
Silverlight
25
Live Services Synchronizing Life
Live Search 2.0 Ad Source
Ad Source
Live Services Synchronizing Life
• Opt into Ad Center • Integrate ads using the XML or JSON APIs Query String
Description
Ad.AdUnitId
Your adCenter Unit ID
Ad.PropertyId
Your adCenter Property ID
Ad.Pagenumber
The page number requested
Ad.SBadCount
Number of sidebar ads requested
Ad.MLadCount
Number of mainline ads requested
Ad Source
Live Services Synchronizing Life
Live Services Synchronizing Life
RSS
RSS • Does not require AppID
http://api.search.live.com/rss.aspx? source=web&query=sushi+los %20angeles • View in any RSS reader
Live Services Synchronizing Life
Subscribe to the Feed
Live Services Synchronizing Life
Summary • • • •
Embed custom search into apps Retrieve different sources Use XML or JSON results Use SOAP
Live Services Synchronizing Life
Questions?
Live Services Synchronizing Life
Discussion
Live Services Synchronizing Life
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.