gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:38:07 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com