Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 403 Forbidden #32

Closed
AngelSotomayor opened this issue Dec 16, 2015 · 141 comments
Closed

Error 403 Forbidden #32

AngelSotomayor opened this issue Dec 16, 2015 · 141 comments

Comments

@AngelSotomayor
Copy link

Till yesterday everything was working perfectly with your translator, but today I'm getting the next error:
Fatal error: Uncaught exception 'ErrorException' with message 'Client error response [url] http://translate.google.com/translate_a/t [status code] 403 [reason phrase] Forbidden'
And the stack trace says that comes from lines 215, 247 and 143 of the method TranslateClient.php.
Do you suspect which is the problem?

@AngelSotomayor
Copy link
Author

Finally, its working again, so I suppose that was an error from google maybe?

@Stichoza
Copy link
Owner

Yup, I guess it was Google's problem or maybe some network related. Here is a list of exceptions that you might get. You can wrap your code in a try-catch block to handle this kind of exceptions.

@AngelSotomayor
Copy link
Author

Could it be that google has banned or restricted my ip?

@josepamado
Copy link

It is not working for me. I think they have changed the URL from http://translate.google.com/translate_a/t to https://translate.google.com/#[lang_from]/[lang_to]/[text_to_translate]

@tehmaestro
Copy link
Contributor

It's not working for me either, and I've just tried this library. I guess something changed. I wasn't able to fix it yet, I've been playing with the query params.

@Stichoza
Copy link
Owner

I run tests several times and they fail randomly.

  • .........E....
  • .............. (no errors)
  • ......E..E.E..

and so on. It's weird 😒

@Stichoza
Copy link
Owner

I'll push a dummy commit to see what will travis get.
Update: Travis tests failed (in random manner, as mentioned above)

@quanglam2807
Copy link
Contributor

Google just updated the API to add a tk param, but it always changes so I think we need to figure out how to generate it.

https://translate.google.com/translate_a/single?client=t&sl=en&tl=it&hl=en&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=UTF-8&oe=UTF-8&otf=1&ssel=0&tsel=0&kc=1&tk=685310.807246&q=c

tk=685310.807246

@laan
Copy link

laan commented Dec 17, 2015

I get the same error. Is there some solutions?

@tehmaestro
Copy link
Contributor

I confirm it is the tk parameter. This parameter depends on the string, and it seems it is case sensitive.
Just to confirm, when translating the following, do you guys get the same tk value ?

English to French
- Hello : 590327.992320
- dog : 859113.736862
- Dog: 474088.73311
- cat: 534316.918171

@gaozhitw
Copy link

@tehmaestro I got the same value

@dhrubo001
Copy link

Yes i am facing the same problm..its worked properly yesterday but from today morning...it's giving the same problem....wat's the issue

@quanglam2807
Copy link
Contributor

@tehmaestro I think it also depends on something else. Did you try to use different browsers?

@tehmaestro
Copy link
Contributor

EDIT: Actually no, there are the same values, regardless of the browser or computer. It might depend on the browser version though or operating system, I think.
EDIT2: I get same values on different browsers, versions, OSs

@quanglam2807
Copy link
Contributor

So what should we do now? Big trouble...

@Stichoza
Copy link
Owner

I might be wrong, but as I see the tk is generated on front-end using js. I hope we'll find something useful in that super obfuscated js files

@Stichoza
Copy link
Owner

I copied the url from network log and it works from any browser an even from HTTP request testers.

In addition to tk, there are multiple dt params added. Removing them causes the translation to fail. I have no clue what those dt's mean

@tehmaestro
Copy link
Contributor

Here are my findings. The part which generates the tk parameter in javascript is the TL function here:

    var QL = function(a) {
        return function() {
            return a
        }
    }
      , RL = function(a, b) {
        for (var c = 0; c < b.length - 2; c += 3) {
            var d = b.charAt(c + 2)
              , d = d >= t ? d.charCodeAt(0) - 87 : Number(d)
              , d = b.charAt(c + 1) == Tb ? a >>> d : a << d;
            a = b.charAt(c) == Tb ? a + d & 4294967295 : a ^ d
        }
        return a
    }
      , SL = null 
      , TL = function(a) {
        var b;
        if (null  === SL) {
            var c = QL(String.fromCharCode(84));
            b = QL(String.fromCharCode(75));
            c = [c(), c()];
            c[1] = b();
            SL = Number(window[c.join(b())]) || 0
        }
        b = SL;
        var d = QL(String.fromCharCode(116))
          , c = QL(String.fromCharCode(107))
          , d = [d(), d()];
        d[1] = c();
        for (var c = cb + d.join(k) + 
        mf, d = [], e = 0, f = 0; f < a.length; f++) {
            var g = a.charCodeAt(f);
            128 > g ? d[e++] = g : (2048 > g ? d[e++] = g >> 6 | 192 : (55296 == (g & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ? (g = 65536 + ((g & 1023) << 10) + (a.charCodeAt(++f) & 1023),
            d[e++] = g >> 18 | 240,
            d[e++] = g >> 12 & 63 | 128) : d[e++] = g >> 12 | 224,
            d[e++] = g >> 6 & 63 | 128),
            d[e++] = g & 63 | 128)
        }
        a = b || 0;
        for (e = 0; e < d.length; e++)
            a += d[e],
            a = RL(a, Vb);
        a = RL(a, Ub);
        0 > a && (a = (a & 2147483647) + 2147483648);
        a %= 1E6;
        return c + (a.toString() + dd + (a ^ b))
    }

So, some stuff I discovered. For return c + (a.toString() + dd + (a ^ b)):

   c is '&tk=' string
   dd is '.' string

That would leave a and b to be discovered. It seems that b = window['TKK'] which is always 402874 . Not sure if this changes, but I tested multiple text queries and b's value did not change.

And then there's a. As you can see, there's a line here a = b || 0; which essentially makes a's value b.

d in the code above is a an array with the charcode of each character in the input string.So, for Dog , d is an array with 3 elements, [68, 111, 103].

I think this is the important part:

for (e = 0; e < d.length; e++)
            a += d[e],
            a = RL(a, Vb);
        a = RL(a, Ub);
        0 > a && (a = (a & 2147483647) + 2147483648);
        a %= 1E6;

So, for each number in d array, it adds it to a, which is actually b, and applies RL.
Anyway, maybe somebody can take it further, I kinda stopped here, cause I don't fully understand the operations in RL.

Also, Vb is +-a^+6 operation and Ub is +-3^+b+-f . I know ...

@limonte
Copy link
Contributor

limonte commented Dec 17, 2015

same issue here.

@quanglam2807
Copy link
Contributor

@tehmaestro Nicely done! I have also tried the same thing but I was unable to find the value of the constant. It's really nice that you can do it!
SL = Number(window[c.join(b())]) || 0
This line is also what we need to figure out. Can you share the window values as I'm unable to find them?

@helen5106
Copy link

I have finished this issue.

http://www.liuxiatool.com/t.php?tk=L

function shr32($x, $bits)
{

    if($bits <= 0){
        return $x;
    }
    if($bits >= 32){
        return 0;
    }

    $bin = decbin($x);
    $l = strlen($bin);

    if($l > 32){
        $bin = substr($bin, $l - 32, 32);
    }elseif($l < 32){
        $bin = str_pad($bin, 32, '0', STR_PAD_LEFT);
    }

    return bindec(str_pad(substr($bin, 0, 32 - $bits), 32, '0', STR_PAD_LEFT));
}        

function charCodeAt($str, $index)
{
    $char = mb_substr($str, $index, 1, 'UTF-8');

    if (mb_check_encoding($char, 'UTF-8'))
    {
        $ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
        return hexdec(bin2hex($ret));
    }
    else
    {
        return null;
    }
}


function RL($a, $b)
{
    for($c = 0; $c < strlen($b) - 2; $c +=3) {
        $d = $b{$c+2};
        $d = $d >= 'a' ? charCodeAt($d,0) - 87 : intval($d);
        $d = $b{$c+1} == '+' ? shr32($a, $d) : $a << $d;
        $a = $b{$c} == '+' ? ($a + $d & 4294967295) : $a ^ $d;
    }
    return $a;
}

function TL( $a )
{   
    $b = 402890;
    for ($d = array(), $e = 0, $f = 0; $f < strlen($a); $f++) {
        $g = charCodeAt($a, $f);

        if ( 128 > $g ) {
            $d[$e++] = $g; 
        } else {
            if ( 2048 > $g ) { 
                $d[$e++] = $g >> 6 | 192;
            } else { 
                if ( 55296 == ($g & 64512) && $f + 1 < strlen($a) && 56320 == (charCodeAt($a, $f + 1) & 64512) ) { 

                    $g = 65536 + (($g & 1023) << 10) + (charCodeAt($a, ++$f) & 1023);
                    $d[$e++] = $g >> 18 | 240; 
                    $d[$e++] = $g >> 12 & 63 | 128;
                } else {
                    $d[$e++] = $g >> 12 | 224;
                    $d[$e++] = $g >> 6 & 63 | 128;
                }
            }
            $d[$e++] = $g & 63 | 128;
        }
    }

    $a = $b;
    for ($e = 0; $e < count($d); $e++) {
        $a += $d[$e];
        $a = RL($a, '+-a^+6');
    }
    $a = RL($a, "+-3^+b+-f");
    if (0 > $a) $a = ($a & 2147483647) + 2147483648;
    $a %= pow(10, 6);
    return sprintf('%d.%d', $a, $a ^ $b);
}


$tk = (isset($_GET['tk']) && !empty($_GET['tk'])) ? $_GET['tk'] : 'love';
echo $tk . "=". TL($tk);

@tehmaestro
Copy link
Contributor

Wow, congrats. I can confirm it works!

@Stichoza
Copy link
Owner

@helen5106 wow that's a great work 👍 But I still get 403 errors :( @tehmaestro How do you guys tested this token works?

@quanglam2807
Copy link
Contributor

@helen5106 Awesome! You save my life!

@tehmaestro
Copy link
Contributor

I just added the functions written above in your class, and added the tk param to the request like so:

        $queryArray = array_merge($this->urlParams, [
            'text' => $data,
            'sl'   => $this->sourceLanguage,
            'tl'   => $this->targetLanguage,
            'tk' => $this->TL($data)
        ]);

Of course, this will not work when $data is an array, cause TL expects a string.

@quanglam2807
Copy link
Contributor

@tehmaestro It would be nice if someone can also figure out how to generate TL with an array. I really need it.

@Stichoza
Copy link
Owner

@tehmaestro Great! I'll make some preparation changes to the codebase. May I ask you to send me a pull request after I'm done with that changes?

@laan
Copy link

laan commented Dec 20, 2015

@helen5106 your code works to english. But if the text is UTF-8 chars, it will get the same error. Maybe need some decode. I will try to do this test.

@tehmaestro
Copy link
Contributor

I've fixed the script so it works with UTF-8. I will be sending a pull request next week, just as an example.

@joeforjoomla
Copy link

I think i'm doing the same thing only difference i do it in PHP instead of Javascript, scraping codes directly from the Google Translate page see the code that i posted above:

` /**

  • Generate a valid Google Translate TKK token
    *

  • @access private

  • @return string
    */
    private function TKK() {
    $session = getSessionObject();
    if($sessionGoogleToken = $session->get('engine_google_token')) {
    return $sessionGoogleToken;
    }

    // Random user agents DB
    $userAgents = array (
    "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0",
    "Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/31.0",
    "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20130401 Firefox/31.0",
    "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36",
    "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2224.3 Safari/537.36",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A",
    "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25",
    "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko",
    "Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko",
    "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
    "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)",
    "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)",
    "Mozilla/5.0 (compatible; MSIE 10.0; Macintosh; Intel Mac OS X 10_7_3; Trident/6.0)"
    );
    $ua = $userAgents [rand ( 0, count ( $userAgents ) - 1 )];
    // Format the request header array
    $headers = array (
    'Cache-Control' => 'max-age=0',
    'User-Agent' => $ua,
    'Accept' => 'text/html',
    'Referer' => 'https://translate.google.com/',
    'Accept-Language' => 'en-GB, en'
    );
    // Request API GET
    // Transport wrapper
    $HTTPClient = new HttpRequestObject ();
    $HTTPResponse = $HTTPClient->get ( "https://translate.google.com", $headers );
    $bodyResponsePage = $HTTPResponse->body;

    preg_match('/TKK.*return\s?-?\d+/', $bodyResponsePage, $AandBArray);

    $periodsExploded = explode(';', $AandBArray[0]);

    // First var $a
    $aExploded = explode('\x3d', $periodsExploded[0]);
    $a = $aExploded[1];

    // Second var $b
    $bExploded = explode('\x3d', $periodsExploded[1]);
    $b = $bExploded[1];

    // Third var hours - Unix elapsed
    $hoursExploded = explode('return', $periodsExploded[2]);
    $hoursElapsed = trim($hoursExploded[1]);

    $session->set('engine_google_token', $hoursElapsed . '.' . ($a + $b));

    return $hoursElapsed . '.' . ($a + $b);
    }

    /**

  • Generate a valid Google Translate request token
    *

  • @param string $a

  •      text to translate
    
  • @return string
    */
    private function TL($a) {
    $tkk = explode('.', $this->TKK());
    $b = $tkk[0];

    for($d = array (), $e = 0, $f = 0; $f < mb_strlen ( $a, 'UTF-8' ); $f ++) {
    $g = $this->charCodeAt ( $a, $f );
    if (128 > $g) {
    $d [$e ++] = $g;
    } else {
    if (2048 > $g) {
    $d [$e ++] = $g >> 6 | 192;
    } else {
    if (55296 == ($g & 64512) && $f + 1 < mb_strlen ( $a, 'UTF-8' ) && 56320 == ($this->charCodeAt ( $a, $f + 1 ) & 64512)) {
    $g = 65536 + (($g & 1023) << 10) + ($this->charCodeAt ( $a, ++ $f ) & 1023);
    $d [$e ++] = $g >> 18 | 240;
    $d [$e ++] = $g >> 12 & 63 | 128;
    } else {
    $d [$e ++] = $g >> 12 | 224;
    $d [$e ++] = $g >> 6 & 63 | 128;
    }
    }
    $d [$e ++] = $g & 63 | 128;
    }
    }
    $a = $b;
    for($e = 0; $e < count ( $d ); $e ++) {
    $a += $d [$e];
    $a = $this->RL ( $a, '+-a^+6' );
    }
    $a = $this->RL ( $a, "+-3^+b+-f" );
    $a ^= $tkk[1];
    if (0 > $a) {
    $a = ($a & 2147483647) + 2147483648;
    }
    $a = fmod ( $a, pow ( 10, 6 ) );
    return $a . "." . ($a ^ $b);
    }`

@quanglam2807
Copy link
Contributor

@joomlajoe OK, sorry! I didn't read your code carefully.
Here's mine

let url = "https://translate.google.com"
      return WinJS.xhr({
        url: url,
        responseType: "text"
      }).then(response => {
          return response.response
        })
        .then(body => {
          const startStr = 'TKK=eval(';
          const endStr = ');WEB_TRANSLATION_PATH=';
          const startI = body.indexOf(startStr) + startStr.length;
          const endI = body.indexOf(endStr);
          const tkkEval = body.substring(startI, endI);

          const x = eval(eval(tkkEval));
          return x;
        })

@feokano
Copy link

feokano commented Jun 9, 2016

It's working perfect (with grabbing TKK from google).

@joeforjoomla
Copy link

Hi @quanglam2807 it's still working fine with the usual static values

@clover2008
Copy link

clover2008 commented Jun 10, 2016

@KreerC
Copy link
Contributor

KreerC commented Jun 10, 2016

@clover2008 Why do you want to translate from zh-CN to zh-CN? Also, could you please describe exactly what is wrong?

@clover2008
Copy link

qq 20160610202412

@KreerC
Copy link
Contributor

KreerC commented Jun 10, 2016

@clover2008

Did you test with the library itself? Also, I don't think that there is any support for simplified chinese at the moment.

@helen5106
Copy link

@clover2008

I know you want to translate chinese pinyin to chinese words.

pls change this param:

t?client=webapp

to;

single?client=t

http://www.liuxiatool.com/t.php?sl=zh-CN&tl=zh-CN&q=tamen&p=2&tijioao=submit

@lapinozz
Copy link

Thanks to the help of all you guys I was able to make a C++ version of the token generation code (dropped unicode tho, because of lazyness)

std::string toBasse(int64_t value, int base = 2)
{
    const auto digits = "0123456789abcdefghijklmnopqrstuvwxyz";
    std::string number;

    do
    {
        number = digits[value % base] + number;
        value = (int64_t)(value / base);
    }
    while(value);

    return number;
}

int64_t binToDec(std::string value)
{
    int64_t number = 0;

    int power = 1;
    for(size_t x = value.size() - 1; x > 0; x--)
    {
        number += power * (value[x] == '1');
        power *= 2;
    }

    return number;
}

int shr32(int x, int bits)
{
    if(bits <= 0)
        return x;
    if(bits >= 32)
        return 0;

    auto bin = toBase(x, 2);
    auto l = bin.size();

    if(l > 32)
        bin = bin.substr(l - 32, 32);
    else if(l < 32)
    {
        while(bin.size() < 32)
            bin = '0' + bin;
    }

    bin = bin.substr(0, 32 - bits);

    while(bin.size() < 32)
            bin = '0' + bin;

    return binToDec(bin);
}

int RL(int a, const std::string& b)
{
    for(size_t c = 0; c < b.size() - 2; c += 3)
    {
        int d = b[c + 2];

        if(d >= 'a')
            d -= 87;
        else if(d == '+' || d == '-')
            d = 0;
        else
            d -= '0';

        d = (b[c + 1] == '+' ? shr32(a, d) : a << d);
        a = (b[c] == '+' ? (a + d & 4294967295) : a ^ d);
    }

    return a;
}

std::string generateTranslateToken(std::string query)
{
    uint32_t a = 406398;
    for(const auto c : query)
    {
        a += c;
        a = RL(a, "+-a^+6");
    }
    a = RL(a, "+-3^+b+-f");
    a ^= (561666268 + 1526272306);

    if(a < 0)
        a = (a & 2147483647) + 2147483648;

    a = a % 1000000;
    return std::to_string(a) + "." + std::to_string(a ^ 406398);
}

@matheuss
Copy link

matheuss commented Jul 1, 2016

Hi there :) Thanks to this issue, I came up with a JavaScript module that generates the tk based on a given text 😊 https://github.com/matheuss/google-translate-token

@joeforjoomla
Copy link

joeforjoomla commented Jul 1, 2016

Great work @matheuss !
Any PHP porting of your lib?

@ghost
Copy link

ghost commented Jul 12, 2016

@Skylion007 you can find here the implemetation in Java: http://pastebin.com/G4TJJFNd

@MrS0m30n3
Copy link

Hi,

I also wrote a Python library that uses the Google translate.
The tk_generator.py module is based on the code from this issue.

https://github.com/MrS0m30n3/google-translate

Thank you all for your amazing work!

@kevin-lxh
Copy link

@quanglam2807@lollita Thanks!

@ghost
Copy link

ghost commented Jan 29, 2017

@helen5106 Thank you man good job

@shixiangjun888
Copy link

@helen5106 very good. I expect you improve more and more.

@firekim2
Copy link

firekim2 commented Jul 13, 2017

I made this for python and used php of tastemylife.com

import requests
from sys import argv

_str = argv

sentence_eng = str(_str[1])
sentence_eng.replace(' ','+')
dataset ={'sl':'en','tl':'ko','p':'2'}#for now, set on English to Korean
req_url="http://www.tastemylife.com/gtr.php?sl={0}&tl={1}&p={2}&q=".format(dataset['sl'],dataset['tl'],dataset['p'])
req_url=req_url+sentence_eng

req = requests.get (req_url)
req_json = req.json()
print(req_json['result'])

You can use it in terminal or somewhat as :
$python ---.py "blah blah blah"

parksjin01 added a commit to parksjin01/2017- that referenced this issue Jul 31, 2017
…ere](Stichoza/google-translate-php#32).

If I finish development than I'll change formal google api
@feokano
Copy link

feokano commented Sep 9, 2019

Hello! Today it's not working again for me. Does Google updated TK generation algorithm?

@joeforjoomla
Copy link

Just tested.... it's working for me

@feokano
Copy link

feokano commented Sep 9, 2019

Regardless of ip, it stopped working on all projects, both new and those where nothing has changed for 3 years.

https://translate.google.ru/translate_a/single?client=t&sl=ru&tl=en&hl=en&dt=t&ie=UTF-8&oe=UTF-8&multires=1&otf=0&pc=1&trs=1&ssel=0&tsel=0&sc=1&tk=803532.684373&q=память): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

@joeforjoomla
Copy link

@feokano first of all open a new issue given that this one has been closed.
Then provide some detailed informations to reproduce your issue, given that the url that you posted with the TK value is working correctly.

@frzsombor
Copy link
Contributor

@feokano I can confirm that it's STILL WORKING. There was an update by Google around 23rd Jul 2019, but this project has been updated and working correctly. Please make sure you are using the latest version (v4.0.2 as of now) and use proxies properly to make sure Google doesn't block you. If you are still having problems right now, I'm pretty sure it's not caused by this repo.

@feokano
Copy link

feokano commented Sep 9, 2019

Yes, sorry.
I wrote parser for google.translate long before it was needed to include secret from js, and after - I get response by curl, used only function TL(); from this library.
Whole class work fine, if you using Guzzle to send request.
But today, I don't know why, simple curl request stop working (on any IP, with any User-agent), Google doesn't blocking Me (then open url by Guzzle - it's working) - seems that blocking the way I getting response.
If you open url in browser - you'll get json, but by using php (with ssl-check, or without) - 403 error.
Maybe it's off-topic, I shall looking the answer in Guzzle branch, but what is the difference in the way of sending requests by Guzzle and curl? Cookies, cafile (curl.cainfo) or something else?
I just don't want to shoot from a cannon at sparrows, using huge library beside one line of code.
Help me please to find an answer?

@taiviemthoi
Copy link

hi @helen5106
I am using this endpoint

https://translate.googleapis.com/translate_a/t?anno=3&client=tee&format=html

detail

curl 'https://translate.googleapis.com/translate_a/t?anno=3&client=tee&format=html&v=1.0&key&sl=auto&tl=vi&tc=2&sr=1&tk=740634.884324&mode=1' \
  -H 'authority: translate.googleapis.com' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'accept: */*' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-dest: empty' \
  -H 'accept-language: en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,sw-TZ;q=0.6,sw;q=0.5,es;q=0.4,de;q=0.3' \
  --data-raw 'q=i love you' \
  --compressed

I use Stichoza\GoogleTranslate\Tokens\GoogleTokenGenerator to generate token

generateToken("en", "vi", "i love you") => token: 740634.884324

everything works fine

but when i encode the query and use multi query like this demo, the gen token output is not correct anymore

so, is the gen token function giving the error?

@taiviemthoi
Copy link

taiviemthoi commented Jun 16, 2021

exam code err
$token->generateToken("en", "vi", rawurlencode("Justin Tadlock·"))
=> token = 273364.137386

curl 'https://translate.googleapis.com/translate_a/t?anno=3&client=tee&format=html&v=1.0&key&sl=auto&tl=vi&tc=2&sr=1&tk=273364.137386&mode=1' \
  -H 'authority: translate.googleapis.com' \
  -H 'sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'accept: */*' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-dest: empty' \
  -H 'accept-language: en-US,en;q=0.9,fr-FR;q=0.8,fr;q=0.7,sw-TZ;q=0.6,sw;q=0.5,es;q=0.4,de;q=0.3' \
  --data-raw 'q=%3Ca%20i%3D0%3EJustin%20Tadlock%3C%2Fa%3E%3Ca%20i%3D1%3E%C2%B7%3C%2Fa%3E' \
  --compressed

@shixiangjun888
Copy link

shixiangjun888 commented Jun 23, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests