SlideShare a Scribd company logo
Integrate Search
Function to Your
App using Bing
Search API
Marvin Heng
Twitter : @hmheng
Blog : http://hmheng.pinsland.com
Github: https://github.com/hmheng
Microsoft
Cognitive Service
Pre-requisites
• Created a Xamarin mobile app
• Cognitive Service Account
Integrate Search Function Into Mobile App
1. First, we need to obtain the API key for Bing Search APIs v7. To learn how to get
one, click here.
Integrate Search Function Into Mobile App
2. Secondly, we need to create a Xamarin Cross Platform Mobile App. Don’t have one
yet? Click to learn how to create one!
Integrate Search Function Into Mobile App
3. Thirdly, we need to add a NuGet Packages – Newtonsoft.Json, right click Solution
in the Solution Explorer -> Manage NuGet Packages for Solution…
3b
3a
4b4a
4c
Integrate Search Function Into Mobile App
4. Let’s search Newtonsoft.Json and install it to all the projects.
Integrate Search Function Into Mobile App
5. Now, we need to add some Search Bar components to MainPage.xaml as
specified below.
5
Integrate Search Function Into Mobile App
6. Down below the Grid component, let’s add a list view to show the returned
search result.
6
Integrate Search Function Into Mobile App
7. Create a folder named Models. We will create few classes under this folder later.
7
Integrate Search Function Into Mobile App
8. Right Click “Models” folder -> Add -> select Class from the list. Name the new class
as SearchTagObj.cs.
8a
8b
Integrate Search Function Into Mobile App
9. Create two variables for SearchTagsObj class as below.
…
public class SearchTagsObj
{
public string name { get; set; }
public string content { get; set; }
}
…
Integrate Search Function Into Mobile App
10. Create another new class and name it as WebResultsList.cs.
10a
10b
Integrate Search Function Into Mobile App
11. Create the following variables for WebResultsList class.
…
public class WebResultsList
{
public string name { get; set; }
public string webSearchUrl { get; set; }
public uint totalEstimatedMatches { get; set; }
public ObservableCollection<WebValueObject> value { get;
set; }
public bool someResultsRemoved { get; set; }
}
…
Integrate Search Function Into Mobile App
12. Create another new class and name it as WebValueObject.cs.
12a
12b
Integrate Search Function Into Mobile App
13. Create the following variables for WebValueObject class.
…
public class WebValueObject
{
public string id { get; set; }
public string name { get; set; }
public string url { get; set; }
public string displayUrl { get; set; }
public string snippet { get; set; }
public string dateLastCrawled { get; set; }
public List<SearchTagsObj> searchTags { get; set; }
}
…
Integrate Search Function Into Mobile App
14. Create another class under .Core project, name it as AppConstants.cs and add
three variables as shown below.
…
public class AppConstants
{
public const string OcpApimSubscriptionKey =
"Ocp-Apim-Subscription-Key";
public const string BingWebSearchApiUrl =
"https://api.cognitive.microsoft.com/bing/v7.0/search
public static string BingWebSearchApiKey =
“<YOUR API KEY>";
}
…
14
Integrate Search Function Into Mobile App
15. Now, head to MainPage.xaml.cs, we need to declare few variables.
…
ObservableCollection<WebValueObject> values;
string queryTerm;
HttpClient searchApiClient;
…
Integrate Search Function Into Mobile App
16. Next, in the MainPage constructor, add click event handler for btnSearch &
HttpClient to call WebApi later. Also, create the event handling function.
…
public MainPage()
{
InitializeComponent();
btnSearch.Clicked += BtnSearch_Clicked;
searchApiClient = new HttpClient();
searchApiClient.DefaultRequestHeaders.Add(AppConstants.OcpApimSubscript
ionKey, AppConstants.BingWebSearchApiKey);
}
private async void BtnSearch_Clicked(object sender, EventArgs e)
{
this.queryTerm = txtKeyword.Text;
await LoadData();
}
…
Integrate Search Function Into Mobile App
17. Then, create LoadData function with following codes.
…
protected async Task LoadData()
{
LoadingIndicator.IsVisible = true;
LoadingIndicator.IsRunning = true;
WebResultsList webResults = null;
Boolean error = false;
try{
webResults = await GetQueryResults();
} catch {
error = true;
}
LoadingIndicator.IsVisible = false;
LoadingIndicator.IsRunning = false;
DataTable.IsVisible = true;
if (error) {
await ErrorAndPop("Error", "Error
fetching results", "OK");
}else if
(webResults?.totalEstimatedMatches>0)
{
values = webResults.value;
DataTable.ItemsSource = values;
}else{
await ErrorAndPop("Error", "No
results found", "OK");
}
}
…
Integrate Search Function Into Mobile App
18. After that, create ErrorAndPop function with following codes.
…
protected async Task ErrorAndPop(string title, string text, string button)
{
await DisplayAlert(title, text, button);
Console.WriteLine($"ERROR: {text}");
await Task.Delay(TimeSpan.FromSeconds(0.1d));
await Navigation.PopAsync(true);
}
…
Integrate Search Function Into Mobile App
19. Followed by, create a function GetQueryResults() to call the Bing Search API and
returned the search results.
…
async Task<WebResultsList> GetQueryResults(){
var queryString = System.Net.WebUtility.UrlEncode(queryTerm);
string uri = AppConstants.BingWebSearchApiUrl + $"count=20&mkt=en-
US&q={queryString}&responseFilter=Webpages&setLang=en";
WebResultsList webResults = null;
HttpResponseMessage httpResponseMessage = await
searchApiClient.GetAsync(uri); var responseContentString = await
httpResponseMessage.Content.ReadAsStringAsync();
JObject json = JObject.Parse(responseContentString);
JToken resultBlock = json.SelectToken("$.webPages");
if (resultBlock != null){
webResults =
JsonConvert.DeserializeObject<WebResultsList>(resultBlock.ToString());
}
return webResults;
}
…
Integrate Search Function Into Mobile App
20. Last but not least, create an event handler - ItemSelectedEventHandler for
showing the selected web result when user clicked the result item.
…
async void ItemSelectedEventHandler(object sender,
SelectedItemChangedEventArgs e){
if (e.SelectedItem == null) { return; }
WebView webView = new WebView
{
Source = new UrlWebViewSource{Url = ((WebValueObject)e.SelectedItem).url },
VerticalOptions = LayoutOptions.FillAndExpand
};
// Display the WebView
await Navigation.PushAsync(new ContentPage{
Content = webView, Title = ((WebValueObject)e.SelectedItem).name
});
// Deselect Item
((ListView)sender).SelectedItem = null;
}
…
Integrate Search Function Into Mobile App
21. Let’s compile and run it on your mobile device. Try to see what would happen
when enter some keywords to search!
It’s so easy!
Integrating Search function to Your App is So Easy!
Integrate Search
Function to Your
App using Bing
Search API
Marvin Heng
Twitter : @hmheng
Blog : http://hmheng.pinsland.com
Github: https://github.com/hmheng
Microsoft
Cognitive Service

More Related Content

What's hot

RxJS: A Beginner & Expert's Perspective - ng-conf 2017
RxJS: A Beginner & Expert's Perspective - ng-conf 2017RxJS: A Beginner & Expert's Perspective - ng-conf 2017
RxJS: A Beginner & Expert's Perspective - ng-conf 2017
Tracy Lee
 
Mixpanel
MixpanelMixpanel
Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018
James Thompson
 
Webhooks
WebhooksWebhooks
Creating a server side web app
Creating a server side web appCreating a server side web app
Creating a server side web appjeremyk23
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
Dipendra Shekhawat
 
Page life cycle IN ASP.NET
Page life cycle IN ASP.NETPage life cycle IN ASP.NET
Page life cycle IN ASP.NET
Sireesh K
 
The Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + AngularThe Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + Angular
Tracy Lee
 
Web Os Hands On
Web Os Hands OnWeb Os Hands On
Web Os Hands On
360|Conferences
 
Don't let your mobile app get lost - iOS Spotlight and App Indexing
Don't let your mobile app get lost  - iOS Spotlight and App IndexingDon't let your mobile app get lost  - iOS Spotlight and App Indexing
Don't let your mobile app get lost - iOS Spotlight and App Indexing
James Montemagno
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
Tracy Lee
 
React: JSX and Top Level API
React: JSX and Top Level APIReact: JSX and Top Level API
React: JSX and Top Level API
Fabio Biondi
 
Creating asynchronous flows on AWS
Creating asynchronous flows on AWSCreating asynchronous flows on AWS
Creating asynchronous flows on AWS
Metin Kale
 
The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...
The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...
The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...AspDotNetStorefront
 
Ite express labs
Ite express labsIte express labs
Ite express labs
Aeshan Wijetunge
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Chun-Kai Wang
 
Declaring Server App Components in Pure Java
Declaring Server App Components in Pure JavaDeclaring Server App Components in Pure Java
Declaring Server App Components in Pure Java
Atlassian
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with react
Amit Thakkar
 
Web Hooks
Web HooksWeb Hooks
Web Hooks
Jeff Lindsay
 
Bootiful Development with Spring Boot and Angular - RWX 2018
Bootiful Development with Spring Boot and Angular - RWX 2018Bootiful Development with Spring Boot and Angular - RWX 2018
Bootiful Development with Spring Boot and Angular - RWX 2018
Matt Raible
 

What's hot (20)

RxJS: A Beginner & Expert's Perspective - ng-conf 2017
RxJS: A Beginner & Expert's Perspective - ng-conf 2017RxJS: A Beginner & Expert's Perspective - ng-conf 2017
RxJS: A Beginner & Expert's Perspective - ng-conf 2017
 
Mixpanel
MixpanelMixpanel
Mixpanel
 
Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018Interfaces Not Required — RubyHACK 2018
Interfaces Not Required — RubyHACK 2018
 
Webhooks
WebhooksWebhooks
Webhooks
 
Creating a server side web app
Creating a server side web appCreating a server side web app
Creating a server side web app
 
Creating web api and consuming- part 1
Creating web api and consuming- part 1Creating web api and consuming- part 1
Creating web api and consuming- part 1
 
Page life cycle IN ASP.NET
Page life cycle IN ASP.NETPage life cycle IN ASP.NET
Page life cycle IN ASP.NET
 
The Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + AngularThe Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + Angular
 
Web Os Hands On
Web Os Hands OnWeb Os Hands On
Web Os Hands On
 
Don't let your mobile app get lost - iOS Spotlight and App Indexing
Don't let your mobile app get lost  - iOS Spotlight and App IndexingDon't let your mobile app get lost  - iOS Spotlight and App Indexing
Don't let your mobile app get lost - iOS Spotlight and App Indexing
 
RxJS - The Basics & The Future
RxJS - The Basics & The FutureRxJS - The Basics & The Future
RxJS - The Basics & The Future
 
React: JSX and Top Level API
React: JSX and Top Level APIReact: JSX and Top Level API
React: JSX and Top Level API
 
Creating asynchronous flows on AWS
Creating asynchronous flows on AWSCreating asynchronous flows on AWS
Creating asynchronous flows on AWS
 
The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...
The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...
The Design of Motion - Creating Movement without Flash - Jesse Hodges, AspDot...
 
Ite express labs
Ite express labsIte express labs
Ite express labs
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Declaring Server App Components in Pure Java
Declaring Server App Components in Pure JavaDeclaring Server App Components in Pure Java
Declaring Server App Components in Pure Java
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with react
 
Web Hooks
Web HooksWeb Hooks
Web Hooks
 
Bootiful Development with Spring Boot and Angular - RWX 2018
Bootiful Development with Spring Boot and Angular - RWX 2018Bootiful Development with Spring Boot and Angular - RWX 2018
Bootiful Development with Spring Boot and Angular - RWX 2018
 

Similar to AI: Integrate Search Function into Your App Using Bing Search API.

Android Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdfAndroid Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdf
SudhanshiBakre1
 
AI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You TypedAI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You Typed
Marvin Heng
 
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on AndroidMobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Alberto Ruibal
 
Opticon 2015 - Getting Started with the Optimizely Developer Platform
Opticon 2015 - Getting Started with the Optimizely Developer PlatformOpticon 2015 - Getting Started with the Optimizely Developer Platform
Opticon 2015 - Getting Started with the Optimizely Developer Platform
Optimizely
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
NgLQun
 
Cloud Messaging Flutter
Cloud Messaging FlutterCloud Messaging Flutter
Cloud Messaging Flutter
MuhammadAli408757
 
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Amazon Web Services
 
Angular resolver tutorial
Angular resolver tutorialAngular resolver tutorial
Angular resolver tutorial
Katy Slemon
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
Yevgeniy Brikman
 
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Sittiphol Phanvilai
 
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptxSlide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
raditya gumay
 
BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!
Craig Schumann
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
ShaiAlmog1
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
Mek Srunyu Stittri
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services Rock
Peter Friese
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
Daniel Bryant
 
Knowing is Understanding: A road trip through Google analytics for Windows Ph...
Knowing is Understanding: A road trip through Google analytics for Windows Ph...Knowing is Understanding: A road trip through Google analytics for Windows Ph...
Knowing is Understanding: A road trip through Google analytics for Windows Ph...
blugri software + services BVBA
 
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv Startup Club
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
mharkus
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
Sergio Nakamura
 

Similar to AI: Integrate Search Function into Your App Using Bing Search API. (20)

Android Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdfAndroid Quiz App – Test Your IQ.pdf
Android Quiz App – Test Your IQ.pdf
 
AI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You TypedAI: Mobile Apps That Understands Your Intention When You Typed
AI: Mobile Apps That Understands Your Intention When You Typed
 
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on AndroidMobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
Mobile 2.0 Open Ideas WorkShop: Building Social Media Enabled Apps on Android
 
Opticon 2015 - Getting Started with the Optimizely Developer Platform
Opticon 2015 - Getting Started with the Optimizely Developer PlatformOpticon 2015 - Getting Started with the Optimizely Developer Platform
Opticon 2015 - Getting Started with the Optimizely Developer Platform
 
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptxLecture 12 - Maps, AR_VR_aaaaHardware.pptx
Lecture 12 - Maps, AR_VR_aaaaHardware.pptx
 
Cloud Messaging Flutter
Cloud Messaging FlutterCloud Messaging Flutter
Cloud Messaging Flutter
 
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
Selling Physical GoodsThrough Apps & Other Monetization Strategies (MBL306) |...
 
Angular resolver tutorial
Angular resolver tutorialAngular resolver tutorial
Angular resolver tutorial
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]Introduction to Firebase [Google I/O Extended Bangkok 2016]
Introduction to Firebase [Google I/O Extended Bangkok 2016]
 
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptxSlide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
Slide Deck - Shift Left Beyond App Performance Improvement at Gojek_.pptx
 
BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!BP204 - Take a REST and put your data to work with APIs!
BP204 - Take a REST and put your data to work with APIs!
 
Introduction to Spring Boot.pdf
Introduction to Spring Boot.pdfIntroduction to Spring Boot.pdf
Introduction to Spring Boot.pdf
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
Google Play Services Rock
Google Play Services RockGoogle Play Services Rock
Google Play Services Rock
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
 
Knowing is Understanding: A road trip through Google analytics for Windows Ph...
Knowing is Understanding: A road trip through Google analytics for Windows Ph...Knowing is Understanding: A road trip through Google analytics for Windows Ph...
Knowing is Understanding: A road trip through Google analytics for Windows Ph...
 
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
Lviv MDDay 2014. Ігор Коробка “забезпечення базової безпеки в андроїд аплікац...
 
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
GDG GeorgeTown Devfest 2014 Presentation: Android Wear: A Developer's Perspec...
 
Introduction to React for Frontend Developers
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
 

More from Marvin Heng

Accelerating Personal Development through Microsoft Certifications
Accelerating Personal Development through Microsoft CertificationsAccelerating Personal Development through Microsoft Certifications
Accelerating Personal Development through Microsoft Certifications
Marvin Heng
 
Microsoft BotFramework - Global AI Bootcamp Nepal 2022
Microsoft BotFramework - Global AI Bootcamp Nepal 2022Microsoft BotFramework - Global AI Bootcamp Nepal 2022
Microsoft BotFramework - Global AI Bootcamp Nepal 2022
Marvin Heng
 
Microsoft Cognitive Services at a Glance
Microsoft Cognitive Services at a GlanceMicrosoft Cognitive Services at a Glance
Microsoft Cognitive Services at a Glance
Marvin Heng
 
Create real value in your business process by automated data and form extraction
Create real value in your business process by automated data and form extractionCreate real value in your business process by automated data and form extraction
Create real value in your business process by automated data and form extraction
Marvin Heng
 
A Journey with Microsoft Cognitive Service I
A Journey with Microsoft Cognitive Service IA Journey with Microsoft Cognitive Service I
A Journey with Microsoft Cognitive Service I
Marvin Heng
 
A Journey With Microsoft Cognitive Services II
A Journey With Microsoft Cognitive Services IIA Journey With Microsoft Cognitive Services II
A Journey With Microsoft Cognitive Services II
Marvin Heng
 
AI and App Accessibility
AI and App AccessibilityAI and App Accessibility
AI and App Accessibility
Marvin Heng
 
What's New With Azure AI
What's New With Azure AIWhat's New With Azure AI
What's New With Azure AI
Marvin Heng
 
Intelligent Assistant with Microsoft BotFramework
Intelligent Assistant with Microsoft BotFrameworkIntelligent Assistant with Microsoft BotFramework
Intelligent Assistant with Microsoft BotFramework
Marvin Heng
 
Using AI to solve business challenges
Using AI to solve business challengesUsing AI to solve business challenges
Using AI to solve business challenges
Marvin Heng
 
Intelligent Mobile App with Azure Custom Vision
Intelligent Mobile App with Azure Custom VisionIntelligent Mobile App with Azure Custom Vision
Intelligent Mobile App with Azure Custom Vision
Marvin Heng
 
Azure Cognitive Services for Developers
Azure Cognitive Services for DevelopersAzure Cognitive Services for Developers
Azure Cognitive Services for Developers
Marvin Heng
 
Bot & AI - A Bot for Productivity
Bot & AI - A Bot for ProductivityBot & AI - A Bot for Productivity
Bot & AI - A Bot for Productivity
Marvin Heng
 
Artificial Intelligence - Tell You What I See
Artificial Intelligence - Tell You What I SeeArtificial Intelligence - Tell You What I See
Artificial Intelligence - Tell You What I See
Marvin Heng
 
Handwriting Detection with Microsoft Cognitive Services
Handwriting Detection with Microsoft Cognitive ServicesHandwriting Detection with Microsoft Cognitive Services
Handwriting Detection with Microsoft Cognitive Services
Marvin Heng
 
Create a Q&A Bot to Serve Your Customers
Create a Q&A Bot to Serve Your CustomersCreate a Q&A Bot to Serve Your Customers
Create a Q&A Bot to Serve Your Customers
Marvin Heng
 
Facial Analysis with Angular Web App & ASP.NET Core
Facial Analysis with Angular Web App & ASP.NET CoreFacial Analysis with Angular Web App & ASP.NET Core
Facial Analysis with Angular Web App & ASP.NET Core
Marvin Heng
 
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKitAI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
Marvin Heng
 
AI/ML/DL: Getting Started with Machine Learning on Azure
AI/ML/DL: Getting Started with Machine Learning on AzureAI/ML/DL: Getting Started with Machine Learning on Azure
AI/ML/DL: Getting Started with Machine Learning on Azure
Marvin Heng
 
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & AzureArtificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Marvin Heng
 

More from Marvin Heng (20)

Accelerating Personal Development through Microsoft Certifications
Accelerating Personal Development through Microsoft CertificationsAccelerating Personal Development through Microsoft Certifications
Accelerating Personal Development through Microsoft Certifications
 
Microsoft BotFramework - Global AI Bootcamp Nepal 2022
Microsoft BotFramework - Global AI Bootcamp Nepal 2022Microsoft BotFramework - Global AI Bootcamp Nepal 2022
Microsoft BotFramework - Global AI Bootcamp Nepal 2022
 
Microsoft Cognitive Services at a Glance
Microsoft Cognitive Services at a GlanceMicrosoft Cognitive Services at a Glance
Microsoft Cognitive Services at a Glance
 
Create real value in your business process by automated data and form extraction
Create real value in your business process by automated data and form extractionCreate real value in your business process by automated data and form extraction
Create real value in your business process by automated data and form extraction
 
A Journey with Microsoft Cognitive Service I
A Journey with Microsoft Cognitive Service IA Journey with Microsoft Cognitive Service I
A Journey with Microsoft Cognitive Service I
 
A Journey With Microsoft Cognitive Services II
A Journey With Microsoft Cognitive Services IIA Journey With Microsoft Cognitive Services II
A Journey With Microsoft Cognitive Services II
 
AI and App Accessibility
AI and App AccessibilityAI and App Accessibility
AI and App Accessibility
 
What's New With Azure AI
What's New With Azure AIWhat's New With Azure AI
What's New With Azure AI
 
Intelligent Assistant with Microsoft BotFramework
Intelligent Assistant with Microsoft BotFrameworkIntelligent Assistant with Microsoft BotFramework
Intelligent Assistant with Microsoft BotFramework
 
Using AI to solve business challenges
Using AI to solve business challengesUsing AI to solve business challenges
Using AI to solve business challenges
 
Intelligent Mobile App with Azure Custom Vision
Intelligent Mobile App with Azure Custom VisionIntelligent Mobile App with Azure Custom Vision
Intelligent Mobile App with Azure Custom Vision
 
Azure Cognitive Services for Developers
Azure Cognitive Services for DevelopersAzure Cognitive Services for Developers
Azure Cognitive Services for Developers
 
Bot & AI - A Bot for Productivity
Bot & AI - A Bot for ProductivityBot & AI - A Bot for Productivity
Bot & AI - A Bot for Productivity
 
Artificial Intelligence - Tell You What I See
Artificial Intelligence - Tell You What I SeeArtificial Intelligence - Tell You What I See
Artificial Intelligence - Tell You What I See
 
Handwriting Detection with Microsoft Cognitive Services
Handwriting Detection with Microsoft Cognitive ServicesHandwriting Detection with Microsoft Cognitive Services
Handwriting Detection with Microsoft Cognitive Services
 
Create a Q&A Bot to Serve Your Customers
Create a Q&A Bot to Serve Your CustomersCreate a Q&A Bot to Serve Your Customers
Create a Q&A Bot to Serve Your Customers
 
Facial Analysis with Angular Web App & ASP.NET Core
Facial Analysis with Angular Web App & ASP.NET CoreFacial Analysis with Angular Web App & ASP.NET Core
Facial Analysis with Angular Web App & ASP.NET Core
 
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKitAI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
AI/ML/DL: Introduction to Deep Learning with Cognitive ToolKit
 
AI/ML/DL: Getting Started with Machine Learning on Azure
AI/ML/DL: Getting Started with Machine Learning on AzureAI/ML/DL: Getting Started with Machine Learning on Azure
AI/ML/DL: Getting Started with Machine Learning on Azure
 
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & AzureArtificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
Artificial Intelligent: Intelligent Bot With Microsoft Bot Framework & Azure
 

Recently uploaded

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

AI: Integrate Search Function into Your App Using Bing Search API.

  • 1. Integrate Search Function to Your App using Bing Search API Marvin Heng Twitter : @hmheng Blog : http://hmheng.pinsland.com Github: https://github.com/hmheng Microsoft Cognitive Service
  • 2. Pre-requisites • Created a Xamarin mobile app • Cognitive Service Account
  • 3. Integrate Search Function Into Mobile App 1. First, we need to obtain the API key for Bing Search APIs v7. To learn how to get one, click here.
  • 4. Integrate Search Function Into Mobile App 2. Secondly, we need to create a Xamarin Cross Platform Mobile App. Don’t have one yet? Click to learn how to create one!
  • 5. Integrate Search Function Into Mobile App 3. Thirdly, we need to add a NuGet Packages – Newtonsoft.Json, right click Solution in the Solution Explorer -> Manage NuGet Packages for Solution… 3b 3a
  • 6. 4b4a 4c Integrate Search Function Into Mobile App 4. Let’s search Newtonsoft.Json and install it to all the projects.
  • 7. Integrate Search Function Into Mobile App 5. Now, we need to add some Search Bar components to MainPage.xaml as specified below. 5
  • 8. Integrate Search Function Into Mobile App 6. Down below the Grid component, let’s add a list view to show the returned search result. 6
  • 9. Integrate Search Function Into Mobile App 7. Create a folder named Models. We will create few classes under this folder later. 7
  • 10. Integrate Search Function Into Mobile App 8. Right Click “Models” folder -> Add -> select Class from the list. Name the new class as SearchTagObj.cs. 8a 8b
  • 11. Integrate Search Function Into Mobile App 9. Create two variables for SearchTagsObj class as below. … public class SearchTagsObj { public string name { get; set; } public string content { get; set; } } …
  • 12. Integrate Search Function Into Mobile App 10. Create another new class and name it as WebResultsList.cs. 10a 10b
  • 13. Integrate Search Function Into Mobile App 11. Create the following variables for WebResultsList class. … public class WebResultsList { public string name { get; set; } public string webSearchUrl { get; set; } public uint totalEstimatedMatches { get; set; } public ObservableCollection<WebValueObject> value { get; set; } public bool someResultsRemoved { get; set; } } …
  • 14. Integrate Search Function Into Mobile App 12. Create another new class and name it as WebValueObject.cs. 12a 12b
  • 15. Integrate Search Function Into Mobile App 13. Create the following variables for WebValueObject class. … public class WebValueObject { public string id { get; set; } public string name { get; set; } public string url { get; set; } public string displayUrl { get; set; } public string snippet { get; set; } public string dateLastCrawled { get; set; } public List<SearchTagsObj> searchTags { get; set; } } …
  • 16. Integrate Search Function Into Mobile App 14. Create another class under .Core project, name it as AppConstants.cs and add three variables as shown below. … public class AppConstants { public const string OcpApimSubscriptionKey = "Ocp-Apim-Subscription-Key"; public const string BingWebSearchApiUrl = "https://api.cognitive.microsoft.com/bing/v7.0/search public static string BingWebSearchApiKey = “<YOUR API KEY>"; } … 14
  • 17. Integrate Search Function Into Mobile App 15. Now, head to MainPage.xaml.cs, we need to declare few variables. … ObservableCollection<WebValueObject> values; string queryTerm; HttpClient searchApiClient; …
  • 18. Integrate Search Function Into Mobile App 16. Next, in the MainPage constructor, add click event handler for btnSearch & HttpClient to call WebApi later. Also, create the event handling function. … public MainPage() { InitializeComponent(); btnSearch.Clicked += BtnSearch_Clicked; searchApiClient = new HttpClient(); searchApiClient.DefaultRequestHeaders.Add(AppConstants.OcpApimSubscript ionKey, AppConstants.BingWebSearchApiKey); } private async void BtnSearch_Clicked(object sender, EventArgs e) { this.queryTerm = txtKeyword.Text; await LoadData(); } …
  • 19. Integrate Search Function Into Mobile App 17. Then, create LoadData function with following codes. … protected async Task LoadData() { LoadingIndicator.IsVisible = true; LoadingIndicator.IsRunning = true; WebResultsList webResults = null; Boolean error = false; try{ webResults = await GetQueryResults(); } catch { error = true; } LoadingIndicator.IsVisible = false; LoadingIndicator.IsRunning = false; DataTable.IsVisible = true; if (error) { await ErrorAndPop("Error", "Error fetching results", "OK"); }else if (webResults?.totalEstimatedMatches>0) { values = webResults.value; DataTable.ItemsSource = values; }else{ await ErrorAndPop("Error", "No results found", "OK"); } } …
  • 20. Integrate Search Function Into Mobile App 18. After that, create ErrorAndPop function with following codes. … protected async Task ErrorAndPop(string title, string text, string button) { await DisplayAlert(title, text, button); Console.WriteLine($"ERROR: {text}"); await Task.Delay(TimeSpan.FromSeconds(0.1d)); await Navigation.PopAsync(true); } …
  • 21. Integrate Search Function Into Mobile App 19. Followed by, create a function GetQueryResults() to call the Bing Search API and returned the search results. … async Task<WebResultsList> GetQueryResults(){ var queryString = System.Net.WebUtility.UrlEncode(queryTerm); string uri = AppConstants.BingWebSearchApiUrl + $"count=20&mkt=en- US&q={queryString}&responseFilter=Webpages&setLang=en"; WebResultsList webResults = null; HttpResponseMessage httpResponseMessage = await searchApiClient.GetAsync(uri); var responseContentString = await httpResponseMessage.Content.ReadAsStringAsync(); JObject json = JObject.Parse(responseContentString); JToken resultBlock = json.SelectToken("$.webPages"); if (resultBlock != null){ webResults = JsonConvert.DeserializeObject<WebResultsList>(resultBlock.ToString()); } return webResults; } …
  • 22. Integrate Search Function Into Mobile App 20. Last but not least, create an event handler - ItemSelectedEventHandler for showing the selected web result when user clicked the result item. … async void ItemSelectedEventHandler(object sender, SelectedItemChangedEventArgs e){ if (e.SelectedItem == null) { return; } WebView webView = new WebView { Source = new UrlWebViewSource{Url = ((WebValueObject)e.SelectedItem).url }, VerticalOptions = LayoutOptions.FillAndExpand }; // Display the WebView await Navigation.PushAsync(new ContentPage{ Content = webView, Title = ((WebValueObject)e.SelectedItem).name }); // Deselect Item ((ListView)sender).SelectedItem = null; } …
  • 23. Integrate Search Function Into Mobile App 21. Let’s compile and run it on your mobile device. Try to see what would happen when enter some keywords to search!
  • 24. It’s so easy! Integrating Search function to Your App is So Easy!
  • 25. Integrate Search Function to Your App using Bing Search API Marvin Heng Twitter : @hmheng Blog : http://hmheng.pinsland.com Github: https://github.com/hmheng Microsoft Cognitive Service