我很难理解 Oauth 验证。我正在尝试使用 bing 的搜索 api。他们要求oauth验证。我有他们给我的主键。我遇到的问题是如何发出请求,提供 oauth 验证 key 。
例如,如果我尝试通过以下方式发出获取请求:
http//api.datamarket.azure.com/Bing/Search?Query=%27xbox%27
我收到一个错误
The authorization type you provided is not supported. Only Basic and OAuth are supported
所以问题是,我是否将我的 key 嵌入到 URL 中,比如
http//api.datamarket.azure.com/Bing/Search?Query=%27xbox%27&authetication="myautherizationkey"
如何提供我的凭据以访问他们的 API?
最佳答案
这不是一个完整的答案,因为我仍然收到“401 Unauthorized”错误,但这是我为 AngularJS 配置 OAuth 的方式。这是用于 Bing 图像搜索。
var accountKey = '/*Your Account Key*/';
var base64EncodedKey = btoa(accountKey);
$http({
method: 'GET',
url: 'https://api.datamarket.azure.com/Bing/Search/v1/Image?Query=%27Pizza%27&$format=JSON',
headers: {'Authorization': 'Bearer ' + base64EncodedKey}
}).success(function(json) {
console.log('Returned: ' + JSON.stringify(json));
}).error(function(err) {
console.log('There was an error retrieving the image JSON: ' + err);
});
这至少消除了授权类型 错误,但我提供帐户 key 的方式似乎仍然存在错误。希望它能帮助您指明正确的方向!
关于oauth - 如何使用 Bing 的搜索 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30270935/