IBM Watson Visual Recognition-由于凭证无效,访问被拒绝 [英] IBM Watson Visual Recognition - Access is denied due to invalid credentials
问题描述
我正在尝试将IBM Watson Visual Recognition工具与nodejs(快速)结合使用. 我遵循了指南,但我无法连接该工具.
I'm trying to use IBM Watson Visual Recognition tool with nodejs (express). I followed the instruction from the guide, but I can't connect with the tool.
var fs = require('fs');
var VisualRecognitionV3 = require('watson-developer-cloud/visual-recognition/v3');
var visualRecognition = new VisualRecognitionV3({
version: '2018-03-19',
api_key: 'api key',
});
var images_file = fs.createReadStream('public/images/fruitbowl.jpg');
var classifier_ids = ["food"];
var params = {
images_file: images_file,
classifier_ids: classifier_ids
};
visualRecognition.classify(params, function(err, response) {
if (err)
console.log(err);
else
var resp = JSON.stringify(response, null, 2)
console.log(JSON.stringify(response, null, 2))
});
当我运行自己的nodejs应用程序时,我收到了此消息
When I run my nodejs app, I got this message
错误:未经授权:由于凭据无效,访问被拒绝.
Error: Unauthorized: Access is denied due to invalid credentials.
有人知道该身份验证问题的解决方案吗?
Does someone know the solution to this authentification problem?
推荐答案
您的仪表板可能看起来像这样,其中列出了您的API密钥.如果您有一堆iam_****
属性,则可能需要使用iam_apikey
而不是api_key
进行身份验证.
Your dashboard likely looks like this with your API key listed. If you have a bunch of iam_****
properties, you probably need to authenticate using the iam_apikey
instead of api_key
.
根据 Watson身份验证文档,您可能应该使用如下代码进行身份验证:
Per the Watson Authentication documentation, you should probably be authenticating with code that looks like this:
const fs = require("fs");
const VisualRecognition = require("watson-developer-cloud/visual-recognition/v3");
const vr = new VisualRecognition({
version: "2018-03-19",
iam_apikey: "MY_API_KEY" // Instead of api_key
});
const images_file = fs.createReadStream("./fruit.jpg");
vr.classify({
images_file,
classifier_ids: ["food"]
}, (err, res) => {
if (err) {
throw err;
}
console.log(JSON.stringify(res));
});
在此图像上使用该代码:维基百科水果,结果如下:
Using that code on this image: Wikipedia Fruit, yields the following:
{
"images": [
{
"classifiers": [
{
"classifier_id": "food",
"name": "food",
"classes": [
{
"class": "non-food",
"score": 0.946
}
]
}
],
"image": "fruit2.jpg"
}
],
"images_processed": 1,
"custom_classes": 0
}
这篇关于IBM Watson Visual Recognition-由于凭证无效,访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!