简体   繁体   中英

Google translate API error

I'm getting the following error while using the Google translate API:

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

I have enabled billing, activated the service, registered my API key and allowed the URL. After a bit of searching, no one has offered a conclusive answer.

The request to Google is called 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've put "{key}" to hide my key.

Does anyone know how to resolve this issue?

Thanks in advance!

我有同样的问题,在我的情况下,我通过在Curl exec之前添加这一行来解决它:

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

According to the Google Translation API docs , it is a paid service. Quote:

Google Translate API is a paid service. For website translations, we encourage you to use the Google Website Translator gadget.

Furthermore, from the FAQ :

Is there any free quota? No, the Google Translate API is only available as a paid service. Please see Pricing and Support for more details. However we do offer the Google Website Translator gadget, which will translate your website without charge.

Also remember you need a valid application key, as stated here (You already have that).

So in short, I think it means you have not set up a pricing/billing plan for your application, yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM