Today, we are going to talk about Bing News Search API of Cognitive Toolkit on Universal Windows Platform, using Apache Cordova cross platform technology.
First, we need to get LUIS API for Bing News Search.
Go to this site and create an account. Use your Azure subscription account.
https://www.microsoft.com/cognitive-services/en-US/subscriptions
Figure: 1
Now, select Bing News from the list given above and get API for Bing News Search API. Afterwards, you can see your Free Bing Search API information from the list given below.
Figure: 2
You can select any Cognitive toolkit API from the link given below.
https://www.microsoft.com/cognitive-services/en-us/Bing-news-search-API/documentation/useanddisplayrequirements
Figure: 3
There is a tool to test different API's of Cognitive toolkit. You can see the tool at the link given below.
https://dev.cognitive.microsoft.com/docs/services/56b43f72cf5ff8098cef380a/operations/56f02400dbe2d91900c68553/console
Figure: 4
Here, on this tool, you need to select Category and Ocp-Apim-Subscription-Key. You can get the subscription key from Cognitive toolkit API site.
Figure: 5
Here, you can see after selecting Category and entering Ocp Subscription Key. You can try to access API and see the response.
Figure: 6
From the response, you can see Response status: 200 OK and you can see JSON object of the response.
Figure: 7
Now, create a Universal Windows Platform app, using Apache Cordova toolkit.
Replace the code of an index page with the code given below.
- <!DOCTYPE html>
- <html>
- <head>
- <title>JSSample</title>
- http:
- </head>
- <body>
-
- $(function() {
- var params = {
-
- "Category": "Sports"
- };
-
- $.ajax({
- url: "https://api.cognitive.microsoft.com/bing/v5.0/news/?" + $.param(params),
- beforeSend: function(xhrObj){
-
- xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","08a7d09e159a4af6b052ce2b97a0f2ae");
- },
- type: "GET",
-
- data: "{body}",
- })
- .done(function(data) {
-
- console.log(data);
- $("#type").html(data._type);
- $("#category").html(data.value[0].category);
- $("#provider").html(data.value[0].provider[0].name);
- $("#date").html(data.value[0].datePublished);
- $("#name").html(data.value[0].name);
- $("#description").html(data.value[0].description);
-
- })
- .fail(function() {
- alert("error");
- });
-
- $('#btn').click(function() {
- alert("Hello");
- });
- });
-
- <h2>Bing News Search API</h2>
- <h3 id="type"></h3>
- <p id="category"></p>
- <p id="provider"></p>
- <p id="date"></p>
- <p id="name"></p>
- <p id="description"></p>
- <input id="btn" type="button" value="button" />
- <pre id="json"></pre>
- </body>
- </html>
Now, run Universal Windows Platform app and see the result, as shown below.
Here, you can see the category, provider info, news type which is Sports, published data, name header and description.