不知道如何查询 Bing/Azure Marketplace API [英] Can't figure out how to query Bing/Azure Marketplace API

查看:23
本文介绍了不知道如何查询 Bing/Azure Marketplace API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你到底是如何使用 Bing API(现在是 Azure Marketplace API)的?是否只支持oAuth?任何人都可以向我展示如何对其进行身份验证的示例吗?文档是无声的,经过一个小时的沮丧之后,我在这里发布了这个问题.

How the heck do you use the Bing API (now Azure Marketplace API)? Does it only support oAuth? Can anyone show me an example of how to authenticate to it? The documentation is silent and after an hour of frustration I'm posting the question here.

这是我想要达到的终点:

Here is the end point I am trying to hit:

https://api.datamarket.azure.com/Bing/Search/v1/Composite?query=sushi&sources=web

这会抛出基本身份验证;如果我取消,我会收到一条错误消息,指出仅支持 Basic 和 oAuth.

This throws up Basic Auth; if I cancel I get an error message saying that only Basic and oAuth are supported.

但是,我的帐户已知的用户名和密码的组合都不适用于 Basic,而且我找不到有关如何将 oAuth 与它结合使用的示例.我设置了一个帐户,我订阅了免费套餐.

However, no combination of username and password known to my account works for Basic, and I can't find an example of how to use oAuth with it. I have an account set up, I have subscribed to the free tier.

推荐答案

经过更多的研究和实验,我终于弄清楚了.这些例子让我很困惑(我认为它们假设了很多关于 Azure 的 SOAPy 约定而不是 REST 的上下文,例如区分大小写和带引号的字符串).也许他们会混淆其他人,所以我在这里发布我的答案:

After doing more research and experiment I was able to figure it out. The examples confused me (I think theyassume a lot of context about Azure's SOAPy conventions over REST, such as case sensitivity and quoted strings). Perhaps they will confuse others so I'm posting my answer here:

function searchBing() {
    var request=require('request');
    var url="https://api.datamarket.azure.com/Bing/Search/v1/Web?Query='sushi'&$format=JSON";
    var key="[your account key]";
    request.get(url, {auth: { user: key, password: key} }, function (error, result) {
        console.log(error, result.body);
    })
}

这篇关于不知道如何查询 Bing/Azure Marketplace API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆