开发者

We can use google-translate without a Google-key?

I found this code in a couple of websites (http://goo.gl/usUSP):

<?php
// Basic request parameters:
// s = source language
// d = destination language
// q = Text to be translated

$s = $_REQUEST['s'];
if(!$s)echo "translate.php?s=en&d=es&q=Hello%20World";
$d = $_REQUEST['d'];
$lang_pair = urlencode($s.'|'.$d);
$q = urlencode($_REQUEST['q']);

// Google's API translator URL
$url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=".$q."&langpair=".$lang_pair;

// Make sure to set CURLOPT_REFERER because Google doesn't like if you leave the referrer out
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.yoursite.com/translate.php");
$body = curl_exec($ch);
curl_close($ch);

$json = json_decode($body, true);
echo $json['responseData']['translatedText'];
?>

Ok basically from what I know, every call using the google translate API must provide a valid key (the user's key).

However from the example code above no key is given and it works! prove: http://juzcode.com/translate.php?s=en&d=es&q=Hello%20World.

I've got 3 questions regarding this issue:

1) How is this even possible? (i'm not very php literate)

2) The limit imposed by Google is 100k charac开发者_Go百科ters per Google-key. The example uses no key. So basically I'd have unlimited usage?

3) Does it violate http://code.google.com/apis/language/translate/terms.html ? (I've tried to read it, really! But I'm no lawyer, I'd just want to be sure)


1) How is this even possible? (i'm not very php literate)

The is the REST API meant for AJAX based calls, not the automated server based API.

2) The limit imposed by Google is 100k characters per Google-key. The example uses no key. So basically I'd have unlimited usage?

3) Does it violate http://code.google.com/apis/language/translate/terms.html ? (I've tried to read it, really! But I'm no lawyer, I'd just want to be sure)

You don't want to do that because:

The Google Translate API must be used for user-generated translations. Automated or batched queries of any kind are strictly prohibited.

using curl from PHP is considered an automated request. Use the Rest API instead. You will need a key.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜