@google-cloud/language issues

I have followed the instructions to install the google-cloud/language npm on wix, and set up all my requirements for Google Cloud. But the error is still there. " Unhandled rejection Error: Could not load the default credentials. Browse to Autenticar para usar bibliotecas de cliente  |  Autenticação  |  Google Cloud for more information ." How should I change my code at the bottom in the jsw in order to make it work? Thanks.

async function quickstart() {
// Imports the Google Cloud client library
const language = require(‘@google-cloud/language’);

// Instantiates a client
const client = new language.LanguageServiceClient(); //<---- Am I missing something here?

// The text to analyze
const text = ‘Hello, world!’;

const document = {
content: text,
type: ‘PLAIN_TEXT’,
};

// Detects the sentiment of the text
const [result] = await client.analyzeSentiment({document: document});
const sentiment = result.documentSentiment;

console.log(Text: ${text});
console.log(Sentiment score: ${sentiment.score});
console.log(Sentiment magnitude: ${sentiment.magnitude});
}

Hey there,

You need to authenticate your call. Take a look at the solution provided in this post .

II read this post 500 times…but still couldn’t get it to work.

Where do I put this line:

const client = new vision.ImageAnnotatorClient({ projectId, credentials })

Do I copy the json file I got from Google and pasted it inside the ( )?

So projectId is the project id you will get from your google cloud account and credentials is an object which contains client_email and private_key which is something you get from the json file you downloaded from Google.


in this format?

This is a backend file right?

You’re on the right track. You have posted all the content inside the json file but you just need the 2 as i have mentioned above.

Also don’t forget the projectId

@shantanukumar847

Like this?

Like this:

var projectId = 'TYPE IN YOUR PROJECT ID HERE';
var credentials = { "private_key": "PASTE KEY VALUE HERE", "client_email": "PASTE EMAIL HERE" };

const client = new vision.ImageAnnotatorClient({ projectId, credentials });

It works now. Thank you!

you’re welcome :slight_smile: