I am trying to implement a small slackbot thing where I want to leverage the google tranlation API, but I struggle to get it to work. I did manage to run a single request, but after that one successful request I constantly get the "403 - Daily Limit Exceeded" message.
I'm using F# and my simple code looks something like this:
module Translation = open Google.Cloud.Translation.V2 let client = TranslationClient.Create() let detectLanguage text = let detection = client.DetectLanguage(text) let res = sprintf "%A %A %A %A" detection.Confidence detection.IsReliable detection.Language detection.Text res
When I call "detectLanguage" I get this exception back:
Unhandled Exception: Google.GoogleApiException: Google.Apis.Requests.RequestError Daily Limit Exceeded  Errors [ Message[Daily Limit Exceeded] Location[ - ] Reason[dailyLimitExceeded] Domain[usageLimits] ] at Google.Apis.Requests.ClientServiceRequest
1.Execute() at Google.Cloud.Translation.V2.TranslationClientImpl.DetectLanguages(IEnumerable1 textItems) at Google.Cloud.Translation.V2.TranslationClient.DetectLanguage(String text)
When I check the console I can't see that any requests has been made to the API, so I'm thinking that it might not be configured correctly. How do I go around and debugging this?
I posted the question in the forum, https://groups.google.com/forum/#!topic/google-translate-api/5JHj3RLrH7o, first and got a comment that I was require to properly authenticate. As far as I've understood the .NET client
TranslationClient.Create() should use the default credentials if I haven't specified any, that works for all the other google tools I use.
TranslationClient.Create will use the default credentials - but in this case it's almost certainly the case that they're the wrong default credentials, assuming you're running this locally. If you're running this on Google Cloud Platform, it shouldn't be a problem - that uses "ambient" credentials that should be fine. (If not, let me know in a comment and we can try to diagnose further.)
If you've obtained default application credentials by running
gcloud auth application-default login or similar, then although it'll be sending your credentials, it will be trying to use up the wrong quota. I won't go into intricate details about why, partly because I'll get it wrong and partly because it's a complicated mess. Sorry about that.
The good news is that it's reasonably easy to fix. Basically, you want to use service account credentials:
GOOGLE_APPLICATION_CREDENTIALSenvironment variable to specify that JSON file's location
The default application credentials will load that credential file and use that to authenticate. It will use the right project for quota, and all should be well.
See more on this question at Stackoverflow