Google translate API error

When using the Google translation API, I get the following error:

{"error": {"errors": [{"domain": "usageLimits", "reason": "accessNotConfigured", "message": "Access Not Configured"}], "code": 403, "message": "Access not configured"}}

I turned on billing, activated the service, registered my API key and resolved the URL. After a short search, no one gave a definitive answer.

A Google request is invoked using CURL below:

$curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_URL,'https://www.googleapis.com/language/translate/v2?userIp=' . $_SERVER['REMOTE_ADDR'] . '&key={MYKEY}&source=en&target=fr&q=hello%20there'); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, 0); $query = curl_exec($curl_handle); $info = curl_getInfo($curl_handle); $error = curl_error($curl_handle); 

Please note: I added "{key}" to hide my key.

Does anyone know how to solve this problem?

Thanks in advance!

+4
source share
2 answers

I had the same problem and in my case I solved it by adding this line before Curl exec:

 curl_setopt($ch, CURLOPT_REFERER, 'INSERT YOUR GOOGLE TRANSLATE API ALLOWED DOMAIN HERE'); 
+1
source

According to the Google Translation API Docs , this is a paid service. Quote:

The Google Translate API is a paid service. To translate to a website, we recommend that you use the Google Translator gadget for the website.

In addition, from the FAQ :

Is there a free quota? No, the Google Translate API is only available as a paid service. See the Pricing and Support section for more information. However, we do offer the Google Translator gadget Google Translator, which will broadcast your site for free.

Also remember that you need a valid application key, as indicated here (it already exists).

In short, I think this means that you have not yet set up a tariff plan / tariff plan for your application.

-1
source

Source: https://habr.com/ru/post/1436137/


All Articles