I have created an OCR project using Node and Google Vision API. The code is pretty simple, there’s just one file called server.js and the image is kept in the same folder but I’m getting an error about a JSON object not containing a client email field.
I have doubled checked my code and ensured all credentials are working and client object is also being accessed (using console.log). I also tried downgrading the version of google vision API. But nothing seems to work. I’m also not able to find any solutions here nor on ChatGPT.
Can someone please help.
My code:
require("dotenv").config();
const projectId = process.env.GOOGLE_CLOUD_PROJECT;
const apiKey = process.env.APIKEY;
const vision = require("@google-cloud/vision");
const client = new vision.ImageAnnotatorClient({
projectId,
credentials: {
apiKey,
},
});
async function extractText(filePath) {
try {
const [image] = await client.annotateImage({
image: {
source: { filename: filePath },
},
features: [{ type: "DOCUMENT_TEXT_DETECTION" }],
});
const text = image.fullTextAnnotation.text;
return text;
} catch (error) {
console.error("Error extracting text:", error);
}
}
extractText("sample.jpg")
.then((text) => {
console.log(text);
})
.catch((error) => {
console.error("Error extracting text:", error);
});
The error:
Error extracting text: Error: The incoming JSON object does not contain a client_email field
at JWT.fromJSON (C:UsersabstCodingReactJsgemini-ocrnode_modulesgoogle-auth-librarybuildsrcauthjwtclient.js:211:19)
at GoogleAuth.fromJSON (C:UsersabstCodingReactJsgemini-ocrnode_modulesgoogle-auth-librarybuildsrcauthgoogleauth.js:454:20)
at GoogleAuth._cacheClientFromJSON (C:UsersabstCodingReactJsgemini-ocrnode_modulesgoogle-auth-librarybuildsrcauthgoogleauth.js:469:29)
at GoogleAuth.getClient (C:UsersabstCodingReactJsgemini-ocrnode_modulesgoogle-auth-librarybuildsrcauthgoogleauth.js:687:22)
at GrpcClient._getCredentials (C:UsersabstCodingReactJsgemini-ocrnode_modulesgoogle-gaxbuildsrcgrpc.js:145:40)
at GrpcClient.createStub (C:UsersabstCodingReactJsgemini-ocrnode_modulesgoogle-gaxbuildsrcgrpc.js:318:34)
undefined
PS C:UsersabstCodingReactJsgemini-ocrbackend>