问题
I am trying to use the google translation api in my application by following these instructions, but having some trouble setting up the authorisation.
I created the service account, got the json file, and set it in with
set GOOGLE_APPLICATION_CREDENTIALS="C:\Users\Bassie\Documents\.credentials\google-translation-api\My Project-d885ebbbe907.json"
After running that command I don't see any output, and I don't see a system environment variable called GOOGLE_APPLICATION_CREDENTIALS
(is that where it should appear?).
When I try running some basic sample code:
System.InvalidOperationException: '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.'
What am I doing wrong?
update
even after manually adding the value to system environment variables, I get the same error.
回答1:
Did you try
echo %GOOGLE_APPLICATION_CREDENTIALS%
If it is not working, then right click on my computer(or This PC) icon, properties, in the advanced tab, click on Environment Variables, add a new variable under system variables.
Then check echo %GOOGLE_APPLICATION_CREDENTIALS%
in command prompt.
回答2:
Sorry for the late answer … Was also stuck on this for about 2 hours until I came across this answer:
Follow this link to the original answer
GoogleCredential cred = GoogleCredential.FromFile("credentials.json");
Channel channel = new Channel(FirestoreClient.DefaultEndpoint.Host,
FirestoreClient.DefaultEndpoint.Port,
cred.ToChannelCredentials());
FirestoreClient client = FirestoreClient.Create(channel);
FirestoreDb db = FirestoreDb.Create("my-project, client);
Check it out caused that's what I used
来源:https://stackoverflow.com/questions/46988843/unable-to-set-google-api-credentials