I just installed the google translate api but when I try to use it within visual studios it gives me this error; `
System.InvalidOperationException HResult=0x80131509 Message=The Application Default Credentials are not available.
They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS
must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
I've had a look around and I can't seem to make sense of it. Would anyone be able to tell me how to solve it please, thank you.
I have no experience with this library or API, but I looked at the documentation you linked to. It looks like the library is looking for a some sort of JSON text file containing the credentials.
I'm going to assume you have that, cause I don't know enough to tell you how to get/create it. I'll also assume you're not running "on Compute Engine, GKE, the App Engine flexible environment, or Cloud Functions".
In this senario, the library is going to look for an environment variable called GOOGLE_APPLICATION_CREDENTIALS
(as you know), which it assumes will contain the path of the JSON file. So all you have to do is set that environment variable before calling any of the methods from this library.
You can use Environment.SetEnvironmentVariable for this. Just call it when your application starts up:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", PathToJSONFile)
User contributions licensed under CC BY-SA 3.0