假设用户提供了卡和电话,并且拥有有效的Azure帐户。创建了一个免费的层服务。(有键和端点,类似xyz.Cogitiveservices.azure.com/bing/V7.0
使用免费的层(每秒3个搜索者,每月最多3个搜索者)(见这里https://azure.microsoft.com/en-us/pricing/details/cognitive-services/ )
是GET还是POST调用?正确的头参数是什么?他们只有不起作用的Python示例。https://docs.microsoft.com/en-us/azure/cognitive-services/bing-web-search/quickstarts/python
问题是如何在R中实现它。
此代码不起作用
library(httr)
token='xxxxx'
server='https://xxxxx.cognitiveservices.azure.com/bing/v7.0/'
url=paste0(server,'search')
response = GET(url = url,
authenticate('',token, type = 'basic'))
response
res = content(response, encoding = 'json')发布于 2020-01-01 04:58:29
对于/search终结点,需要具有非空搜索参数(q)的GET请求。
根本不支持Basic Authentication。相反,如Python示例所示,需要包含订阅密钥的header Ocp-Apim-Subscription-Key。
因此,我使用以下代码成功了。这对你来说也应该是可行的。
library(httr)
server = "https://xxxxx.cognitiveservices.azure.com/bing/v7.0/"
token = "subscription key for Bing Search APIs v7"
search_term = "search term"
url = paste0(server, "search")
response = GET(url = url,
query = list(q = search_term),
add_headers(`Ocp-Apim-Subscription-Key` = token)
)
res = content(response, encoding = "json")
res有关标头和查询参数的详细信息,请参阅Web Search API v7 reference。
https://stackoverflow.com/questions/59220614
复制相似问题