Google Translate API with wget (only one client and connection): Suspected Terms of Service Abuse

Hi

Script

> grep translate .bashrc 
translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }

error

> translate "Ich will schwimmen" de en
{"responseData": null, "responseDetails": "Suspected Terms of Service Abuse. Please see http://code.google.com/apis/errors", "responseStatus": 403}

Quote from Google for Developers: da IA e da nuvem a dispositivos móveis e Web

can you repdroduce? Howto fix?

You must include the HTTP referrer header in your call to the API and you also must have a valid Google API key.

wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}"
Automated requests are prohibited; all requests must be made as a result of an end-user action.

Running translate by hand in a terminal would be okay by that description, but if you wanted to use that function to automate anything, that would definitely be a violation.

You can run the Google Translate AJAX API via an automated program; but you must follow the Google TOS. The TOS has specific requirements such as (1) the HTTP referrer field must be present in all API calls and (2) the client must have an API key (from Google) and (3) the client site must have attribute the translation to Google, etc etc.

We used to run this same API on this site and have a lot of coding experience with it.

1 Like

did I understood right?

  • I can't fake a referer?
  • I need to sign up with Google as dev?

See wget's manual page.

If all you do is fake a referer, google would be within their rights to block you or worse. I'm not sure it'd even work, anyway. There's ways other than referrers to check if you're a person instead of a script.