如何在我的 angular 应用程序中使用 bing 搜索?
how to use bing search in my angular app.?
我有一个单页应用程序,Angular(v5) 用于前端,如何在我的应用程序中使用 bing 搜索?
我已经搜索了很多但没有找到解决方案。
在 official site 可用于 Node.Js
如何将其集成到 angular 中?
谢谢
您将使用 http
API 从您的 angular 应用程序直接使用 API。
请查看 here 中的教程以处理 angular 中的 https 请求。
请查看以下代码片段以获取帮助,
import { Headers, RequestOptions } from '@angular/http';
//your component method
doSearch() {
let subscriptionKey = 'YOUR-SUBSCRIPTION-KEY';
let customConfigId = 'YOUR-CUSTOM-CONFIG-ID';
let searchTerm = 'microsoft';
let headers = new Headers();
headers.append('Ocp-Apim-Subscription-Key', subscriptionKey);
let opts = new RequestOptions();
opts.headers = headers;
// here your url
let url = 'https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/search?' +
'q=' + searchTerm +
'&customconfig=' + customConfigId,
// http rquest
this.http.get(url, opts).subscribe(
res => console.log('handle your response',res.json()),
msg => console.error(`Error: ${msg.status} ${msg.statusText}`)
);
}
记不太清了,不过你可以试试上面的代码片段。
否则,如果您在后端有 node
,则为 Bing Custom Search endpoint
创建您自己的 endpoints
,并使用请求处理程序在您的应用中使用它们。
希望对您有所帮助!!
我有一个单页应用程序,Angular(v5) 用于前端,如何在我的应用程序中使用 bing 搜索?
我已经搜索了很多但没有找到解决方案。
在 official site 可用于 Node.Js
如何将其集成到 angular 中? 谢谢
您将使用 http
API 从您的 angular 应用程序直接使用 API。
请查看 here 中的教程以处理 angular 中的 https 请求。
请查看以下代码片段以获取帮助,
import { Headers, RequestOptions } from '@angular/http';
//your component method
doSearch() {
let subscriptionKey = 'YOUR-SUBSCRIPTION-KEY';
let customConfigId = 'YOUR-CUSTOM-CONFIG-ID';
let searchTerm = 'microsoft';
let headers = new Headers();
headers.append('Ocp-Apim-Subscription-Key', subscriptionKey);
let opts = new RequestOptions();
opts.headers = headers;
// here your url
let url = 'https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/search?' +
'q=' + searchTerm +
'&customconfig=' + customConfigId,
// http rquest
this.http.get(url, opts).subscribe(
res => console.log('handle your response',res.json()),
msg => console.error(`Error: ${msg.status} ${msg.statusText}`)
);
}
记不太清了,不过你可以试试上面的代码片段。
否则,如果您在后端有 node
,则为 Bing Custom Search endpoint
创建您自己的 endpoints
,并使用请求处理程序在您的应用中使用它们。
希望对您有所帮助!!