I'm trying to get a token to use IBM Watson Speech-to-Text in my app. Here's my code:
const { IamAuthenticator } = require('ibm-cloud-sdk-core');
const authenticator = new IamAuthenticator({
apikey: 'myApiKey',
});
authenticator.getToken(function (err, token) {
if (!token) {
console.log('error: ', err);
} else {
// use token
}
});
The error message is authenticator.getToken is not a function
.
The documentation says:
string IBM.Cloud.SDK.Core.Authentication.Iam.IamAuthenticator.GetToken ( )
I've tried both getToken
and GetToken
. Same error message. The code isn't complicated, what am I doing wrong?
This is what worked for me with the latest
ibm-watson
node-sdk,Install node-sdk with this command
Then, use this code snippet in your
app.js
orserver.js
node file to receive the IAM access tokenYou can also directly use the IamAuthenticator with Speech to Text