javascript - 查找 Azure Bing 新闻的 Ocp-Apim-Subscription-Key 时遇到问题

标签 javascript azure bing-api bing-news-search-api

我正在尝试使用 Azure 的 Bing News API 创建成功的请求。以下文档中的屏幕截图表明 Ocp-Apim-Subscription-Key 是必需的 header 。 https://learn.microsoft.com/en-us/rest/api/cognitiveservices-bingsearch/bing-news-api-v7-reference

enter image description here

我已经注册了一个帐户,根据这篇文章 Issue in accessing Bing Custom Web Search API v7该 key 可在 Bing 资源 -> key 和端点中找到:enter image description here

我已经尝试了这两个键,但都不起作用。我收到错误代码 401 由于订阅 key 无效或 API 端点错误而导致访问被拒绝。我注意到这张图片中的端点与 bing 新文档中列出的端点不同。我尝试了图中列出的端点(只是为了看看),但收到了 404 错误。

另一个线程说转到 Azure 门户上的 API 管理。 https://learn.microsoft.com/en-us/answers/questions/62385/please-help-me-to-find-the-process-to-get-ampampam.html

导航到 API 管理菜单后,显示“没有可显示的 API 管理服务”。我可以“创建 API 管理”,但后续表单要求提供似乎非典型的信息才能访问 API。这真的是创建 key 的地方还是我做错了什么?谢谢。

这是我的代码。我尝试使用 Postman 并遇到了同样的错误。

import fetch from 'node-fetch';

function testFetch(){



let response = fetch("https://api.cognitive.microsoft.com/bing/v7.0/news/trendingtopics", {
headers: {
    "Ocp-Apim-Subscription-Key": <redacted-key>,
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  }
}).then(async response => {
  try {
   const data = await response.json()
   console.log('response data?', data)
 } catch(error) {
   console.log('Error happened here!')
   console.error(error)
 }
})


 }

 testFetch()

最佳答案

请使用以下端点 BING_HOST = "https://api.bing.microsoft.com/v7.0/news/search"并查找以下快照。

请按照以下文档进行 bing 新闻搜索。

https://learn.microsoft.com/en-us/bing/search-apis/bing-news-search/overview

关于javascript - 查找 Azure Bing 新闻的 Ocp-Apim-Subscription-Key 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69669840/

相关文章:

javascript - 解析CSS背景属性

c# - 使用 Azure 的 '/' 应用程序中的服务器错误

javascript - 使用 Bing map 突出显示图钉

c# - 如何使用 Bing API 通过 Bing map 搜索特定商店

javascript - 如何使用 firebase firestore 有效地将项目添加到集合中

php - 单击提交按钮时隐藏隐藏的输入值 (php/jquery)

javascript - React - 从多个 API 请求中检索值并将其显示在渲染函数中

Angular5部署到Azure webapp : Content Security Policy

visual-studio - 通过 microsoft webtest 上传文件

php - net::ERR_INCOMPLETE_CHUNKED_ENCODING 是什么意思,我该如何解决?