Can't figure out how to query Bing/Azure Marketplace API

被刻印的时光 ゝ 提交于 2020-01-01 06:39:08

问题


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

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

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.


回答1:


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);
    })
}


来源:https://stackoverflow.com/questions/27261254/cant-figure-out-how-to-query-bing-azure-marketplace-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!