Bing Web Search API v7似乎不起作用

问题描述 投票:0回答:1

我已将JavaScript代码复制到JavaScript文件中,并遵循文件夹格式,但它似乎不起作用。我添加了我的订阅密钥,我已经更改了端点,就像它所说的那样。我想要的只是有人通过一个栏搜索某些东西并点击一个按钮就会显示结果。你知道如何正确地做到这一点吗?我几乎尝试了一切。

我正在尝试.PHP版本

https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/php

php css azure api bing
1个回答
0
投票

我试图按照官方教程qazxsw poi复制代码并使用我的密钥运行。它没有像你那样工作,得到的结果如下图所示。

Quickstart: Use PHP to call the Bing Web Search API

然后,我知道你的问题可能和其他SO线程enter image description here一样。

在Azure上,Bing Web搜索有两种API类型的认知服务,包括Microsoft translator azure are returning null with PHP API(一体化订阅)和All Cognitive Services(仅限Bing搜索),如下图所示。

图1. API类型Bing Search v7(一体化订阅)哪个端点依赖于您的服务区域(All Cognitive Services

Location

图2. API类型enter image description here(仅限Bing搜索)

Bing Search v7

他们使用不同的端点,例如,在我的位置enter image description hereAll Cognitive Service中,端点是Southeast Asia。对于此API类型的Bing Search v7,必须使用https://southeastasia.api.cognitive.microsoft.com/更改最终端点。

因此,在测试成功之后,PHP的官方代码只需要更改两个代码行,如下所示。

  1. 对于使用API​​类型https://southeastasia.api.cognitive.microsoft.com/bing/v7.0/search,代码是: All Cognitive Services
  2. 对于使用API​​类型$accessKey = '<your key for API type of All Cognitive Services>'; $endpoint ='https://<the region of your cognitive service like southeastasia>.api.cognitive.microsoft.com/bing/v7.0/search'; ,代码是: Bing Search v7

对于您评论中的第二个问题,HTML网页和PHP脚本的简单解决方案如下所示。

搜索bar.html

$accessKey = '<your key for API type of Bing Search v7>';
$endpoint = 'https://api.cognitive.microsoft.com/bing/v7.0/search';

search.php:只需要更改<!DOCTYPE html> <html> <body> <form name="bing" method="POST" action="search.php"> <input type="text" name="term"> <input type="submit" value="Search"> </form> </body> </html> 的官方代码。

$term
© www.soinside.com 2019 - 2024. All rights reserved.