Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft cognitive services example in JavaScript

I'm trying to make work this very simple example of the Microsoft Cognitive Services in JavaScript but it's not working. I don't know why. Can some one help me or provide a working example?

I've tried to make the code work both in node and browser (of course with the right modifications to the code).

I'm getting this error in node:

"statusCode":404,"message":"Resource not found".

While if I run the code example [provided on the website][1] I get this error:

Access Denied (401): Access denied due to invalid subscription key

(which is weird cause I'm copying the precise key that has been provide to my in my account page).

const cognitiveServices = require('cognitive-services');

const computerVision = cognitiveServices.computerVision({
        API_KEY: "myAPIkey"
});
const parameters = {
    "language": "unk",
    "detectOrientation": "true",
    "content-type": "application/json"
};
const body = {
    "url": "https://upload.wikimedia.org/wikipedia/commons/2/23/Space_Needle_2011-07-04.jpg"
};

computerVision.ocr({
        parameters,
        body
})
.then((response) => {
        console.log('Got response', response);
})
.catch((err) => {
        console.error('Encountered error making request:', err);
});
like image 562
Jacob Avatar asked Jun 08 '26 19:06

Jacob


1 Answers

Please download version 0.2.0 and it should work.

like image 93
Maria Ines Parnisari Avatar answered Jun 10 '26 08:06

Maria Ines Parnisari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!