Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

"You need to pass auth instance to use gRPC-fallback client in browser. Use OAuth2Client from google-auth-library." #489

Closed
Zanyy opened this issue Nov 18, 2019 · 9 comments
Assignees
Labels
api: vision Issues related to the googleapis/nodejs-vision API. type: question Request for information or clarification. Not an issue. web

Comments

@Zanyy
Copy link

Zanyy commented Nov 18, 2019

Hello Guys,
i'm currently working in Node.js and Electron to program a desktop application that extracts information from an image. ( with help from Google Cloud Vision)
So far so good, but if I now try to authorize myself :

const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient({
  keyFilename: 'client_secrets.json',
 });

I get the Error mentioned in the title.

I've been trying to find a solution to this (simple) problem for two days. The proposed solutions on Github to this issue did not lead to any improvement.

I would be happy to receive your suggestions
Best Regards,
Yannick

@stephenplusplus
Copy link
Contributor

Sorry for the trouble, Yannick. Are you able to do the analyzing on the backend portion of the app, and use a service account JSON key file? Those can be downloaded in the same place as the OAuth-format client_secrets.json.

@stephenplusplus stephenplusplus added the type: question Request for information or clarification. Not an issue. label Nov 18, 2019
@Zanyy
Copy link
Author

Zanyy commented Nov 18, 2019

Hello stephen,
first of all, thank you for the quick response !
Yes, I first wanted to make the solution uncomplicated with Keyfile.json. Just like here:

https://cloud.google.com/blog/products/ai-machine-learning/how-realtimecrm-built-a-business-card-reader-using-machine-learning

But i got the same error again.
I have tried a different API as well to see if it's caused by the APi itself, but didn't change a thing.
maybe there is an easier method for my use case.

To feed you with some information about my project, here is a short summary:
I program a business card reader, which uses a scanned business card to evaluate the photo using the Vision Api and afterwards uses the Natural Language API to split it into categories.

Looking forward to your replies!
Regards

@stephenplusplus
Copy link
Contributor

Interesting! That article links to the authentication guide that shows how to generate an API key, which is the name for a string token-like code, as opposed to a “key file”. They didn’t actually use an “API key”, but a service account key file. Did you try getting a key file like they show in this guide:? https://cloud.google.com/docs/authentication/getting-started#creating_a_service_account

You would store that file locally, then pass it as “keyFilename” in the constructor. Alternatively, you can create an environment variable, “GOOGLE_APPLICATION_CREDENTIALS” that is a path to the file and our library will pick it up automatically.

@bcoe
Copy link
Contributor

bcoe commented Nov 18, 2019

@stephenplusplus @Zanyy browser-side support for our gRPC clients is possible, but experimental. Our peer Alex documents the approach here:

googleapis/google-cloud-node#2933 (comment)

@Zanyy
Copy link
Author

Zanyy commented Nov 19, 2019

Good Morning Stephen and Benjamin!

@stephenplusplus
Yes i have tried that already. I also created an environment variable but unfortunately without success.

I found this Issue_Thread:
https://github.com/googleapis/nodejs-dialogflow/issues/405
Have tried every suggestion but still no changes..

@bcoe I will give it a try, seems interesting!
Haven't seen this solution until now.
I will keep you updated
Regards

@Zanyy
Copy link
Author

Zanyy commented Nov 19, 2019

A little supplement :
I am a quite inexperienced but inquisitive young programmer. It can be, that there are easier ways to authentificate than the way i try to go.
So I can workaround the problem !
Regards

@bcoe
Copy link
Contributor

bcoe commented Nov 19, 2019

@Zanyy with Electron, I believe there are two parts to the application, one that runs browser-side (which would require the fallback) and one that runs in Node.js. I think you could potentially start up a server when your application starts that the browser then talks to, this server would not require the gRPC fallback, and might be the better design;

You're being bitten by the fact that our libraries are designed primarily to run on Node.js not in the browser.

@Zanyy
Copy link
Author

Zanyy commented Nov 22, 2019

Hello all,
sorry for the delayed response, I was working on a workaround.
Decided to use the REST-API, so all my Problems are gone for now.
But thank you @bcoe and @stephenplusplus for your quick help!
Best Regards
Yannick

@bcoe
Copy link
Contributor

bcoe commented Nov 22, 2019

👍 awesome @Zanyy. Let us know if you end up having any more questions.

@bcoe bcoe closed this as completed Nov 22, 2019
@google-cloud-label-sync google-cloud-label-sync bot added the api: vision Issues related to the googleapis/nodejs-vision API. label Jan 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api: vision Issues related to the googleapis/nodejs-vision API. type: question Request for information or clarification. Not an issue. web
Projects
None yet
Development

No branches or pull requests

4 participants